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