*/ class LikeController extends BaseController { final public const ATTRIBUTE_PLAYLIST = 'playlist'; final public const ATTRIBUTE_VIDEO = 'video'; /** * Store a newly created resource. * * @param null $_ * @param array $args * * @throws Exception */ public function store($_, array $args): Model { $validated = $this->validated($args, LikeMutation::class); $playlist = Arr::get($validated, self::ATTRIBUTE_PLAYLIST); $video = Arr::get($validated, self::ATTRIBUTE_VIDEO); if ($playlist instanceof Playlist) { $playlist->like(); return $playlist; } if ($video instanceof Video) { $video->like(); return $video; } throw new Exception('None models detected to like.'); } /** * Remove the specified resource. * * @param null $_ * @param array $args * * @throws Exception */ public function destroy($_, array $args): Model { $validated = $this->validated($args, UnlikeMutation::class); $playlist = Arr::get($validated, self::ATTRIBUTE_PLAYLIST); $video = Arr::get($validated, self::ATTRIBUTE_VIDEO); if ($playlist instanceof Playlist) { $playlist->unlike(); return $playlist; } if ($video instanceof Video) { $video->unlike(); return $video; } throw new Exception('None models detected to unlike.'); } }