repository = $playlist; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\Vidgyor\Playlist\Repositories\Criteria\PlaylistResourceCriteria::class); } /** * Display a list of playlist. * * @return Response */ public function index(PlaylistRequest $request) { $view = $this->response->theme->listView(); if ($this->response->typeIs('json')) { $function = camel_case('get-' . $view); return $this->repository ->setPresenter(\Vidgyor\Playlist\Repositories\Presenter\PlaylistPresenter::class) ->$function(); } $playlists = $this->repository->paginate(); return $this->response->setMetaTitle(trans('playlist::playlist.names')) ->view('playlist::playlist.index', true) ->data(compact('playlists', 'view')) ->output(); } /** * Display playlist. * * @param Request $request * @param Model $playlist * * @return Response */ public function show(PlaylistRequest $request, Playlist $playlist) { if ($playlist->exists) { $view = 'playlist::playlist.show'; } else { $view = 'playlist::playlist.new'; } return $this->response->setMetaTitle(trans('app.view') . ' ' . trans('playlist::playlist.name')) ->data(compact('playlist')) ->view($view, true) ->output(); } /** * Show the form for creating a new playlist. * * @param Request $request * * @return Response */ public function create(PlaylistRequest $request) { $playlist = $this->repository->newInstance([]); return $this->response->setMetaTitle(trans('app.new') . ' ' . trans('playlist::playlist.name')) ->view('playlist::playlist.create', true) ->data(compact('playlist')) ->output(); } /** * Create new playlist. * * @param Request $request * * @return Response */ public function store(PlaylistRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id(); $attributes['user_type'] = user_type(); $playlist = $this->repository->create($attributes); return $this->response->message(trans('messages.success.created', ['Module' => trans('playlist::playlist.name')])) ->code(204) ->status('success') ->url(guard_url('playlist/playlist/' . $playlist->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/playlist/playlist')) ->redirect(); } } /** * Show playlist for editing. * * @param Request $request * @param Model $playlist * * @return Response */ public function edit(PlaylistRequest $request, Playlist $playlist) { return $this->response->setMetaTitle(trans('app.edit') . ' ' . trans('playlist::playlist.name')) ->view('playlist::playlist.edit', true) ->data(compact('playlist')) ->output(); } /** * Update the playlist. * * @param Request $request * @param Model $playlist * * @return Response */ public function update(PlaylistRequest $request, Playlist $playlist) { try { $attributes = $request->all(); $playlist->update($attributes); return $this->response->message(trans('messages.success.updated', ['Module' => trans('playlist::playlist.name')])) ->code(204) ->status('success') ->url(guard_url('playlist/playlist/' . $playlist->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('playlist/playlist/' . $playlist->getRouteKey())) ->redirect(); } } /** * Remove the playlist. * * @param Model $playlist * * @return Response */ public function destroy(PlaylistRequest $request, Playlist $playlist) { try { $playlist->delete(); return $this->response->message(trans('messages.success.deleted', ['Module' => trans('playlist::playlist.name')])) ->code(202) ->status('success') ->url(guard_url('playlist/playlist/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('playlist/playlist/' . $playlist->getRouteKey())) ->redirect(); } } /** * Remove multiple playlist. * * @param Model $playlist * * @return Response */ public function delete(PlaylistRequest $request, $type) { try { $ids = hashids_decode($request->input('ids')); if ($type == 'purge') { $this->repository->purge($ids); } else { $this->repository->delete($ids); } return $this->response->message(trans('messages.success.deleted', ['Module' => trans('playlist::playlist.name')])) ->status("success") ->code(202) ->url(guard_url('playlist/playlist')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/playlist/playlist')) ->redirect(); } } /** * Restore deleted playlists. * * @param Model $playlist * * @return Response */ public function restore(PlaylistRequest $request) { try { $ids = hashids_decode($request->input('ids')); $this->repository->restore($ids); return $this->response->message(trans('messages.success.restore', ['Module' => trans('playlist::playlist.name')])) ->status("success") ->code(202) ->url(guard_url('/playlist/playlist')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/playlist/playlist/')) ->redirect(); } } }