feat: add is_saved function
This commit is contained in:
@@ -117,11 +117,29 @@ public function show($id)
|
|||||||
{
|
{
|
||||||
$media = Media::with(['image', 'category', 'myNote', 'tags'])
|
$media = Media::with(['image', 'category', 'myNote', 'tags'])
|
||||||
->where('id', $id)
|
->where('id', $id)
|
||||||
->where('visibility', 'public')
|
->where(function($query) {
|
||||||
->orWhere('user_id', auth()->id())
|
$query->where('visibility', 'public')
|
||||||
|
->orWhere('user_id', auth()->id());
|
||||||
|
})
|
||||||
->firstOrFail();
|
->firstOrFail();
|
||||||
|
|
||||||
return response()->json($media);
|
return response()->json([
|
||||||
|
'id' => $media->id,
|
||||||
|
'title' => $media->title,
|
||||||
|
'caption' => $media->caption,
|
||||||
|
'type' => $media->type,
|
||||||
|
'file_path' => $media->file_path,
|
||||||
|
'external_url' => $media->external_url,
|
||||||
|
'duration' => $media->duration,
|
||||||
|
'visibility' => $media->visibility,
|
||||||
|
'created_at' => $media->created_at,
|
||||||
|
'updated_at' => $media->updated_at,
|
||||||
|
'image' => $media->image,
|
||||||
|
'category' => $media->category,
|
||||||
|
'tags' => $media->tags,
|
||||||
|
'myNote' => $media->myNote,
|
||||||
|
'is_saved' => $media->is_saved,
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// UPDATE media
|
// UPDATE media
|
||||||
|
|||||||
@@ -54,4 +54,15 @@ public function getUrlAttribute()
|
|||||||
|
|
||||||
return $this->external_url;
|
return $this->external_url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function getIsSavedAttribute()
|
||||||
|
{
|
||||||
|
if (!auth()->check()) return false;
|
||||||
|
|
||||||
|
return $this->savedBy()
|
||||||
|
->where('user_id', auth()->id())
|
||||||
|
->exists();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user