user->playlists); } public function store(PlaylistStoreRequest $request) { $folder = null; if ($request->folder_id) { /** @var PlaylistFolder $folder */ $folder = $this->folderRepository->getOne($request->folder_id); $this->authorize('own', $folder); } try { $playlist = $this->playlistService->createPlaylist( $request->name, $this->user, $folder, Arr::wrap($request->songs), $request->rules ? SmartPlaylistRuleGroupCollection::create(Arr::wrap($request->rules)) : null ); return PlaylistResource::make($playlist); } catch (PlaylistBothSongsAndRulesProvidedException $e) { throw ValidationException::withMessages(['songs' => [$e->getMessage()]]); } } public function update(PlaylistUpdateRequest $request, Playlist $playlist) { $this->authorize('own', $playlist); $folder = null; if ($request->folder_id) { /** @var PlaylistFolder $folder */ $folder = $this->folderRepository->getOne($request->folder_id); $this->authorize('own', $folder); } return PlaylistResource::make( $this->playlistService->updatePlaylist( $playlist, $request->name, $folder, $request->rules ? SmartPlaylistRuleGroupCollection::create(Arr::wrap($request->rules)) : null ) ); } public function destroy(Playlist $playlist) { $this->authorize('own', $playlist); $playlist->delete(); return response()->noContent(); } }