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