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) { return $this->repository ->setPresenter(\Bixo\Viewing\Repositories\Presenter\ViewingPresenter::class) ->paginate(); } /** * Display viewing. * * @param Request $request * @param Model $viewing * * @return Response */ public function show(ViewingRequest $request, Viewing $viewing) { return $viewing->setPresenter(\Bixo\Viewing\Repositories\Presenter\ViewingListPresenter::class); ; } /** * Create new viewing. * * @param Request $request * * @return Response */ public function store(ViewingRequest $request) { try { $data = $request->all(); $data['user_id'] = user_id(); $data['user_type'] = user_type(); $data = $this->repository->create($data); $message = trans('messages.success.created', ['Module' => trans('viewing::viewing.name')]); $code = 204; $status = 'success'; $url = guard_url('viewing/viewing/' . $viewing->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('viewing/viewing'); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Update the viewing. * * @param Request $request * @param Model $viewing * * @return Response */ public function update(ViewingRequest $request, Viewing $viewing) { try { $data = $request->all(); $viewing->update($data); $message = trans('messages.success.updated', ['Module' => trans('viewing::viewing.name')]); $code = 204; $status = 'success'; $url = guard_url('viewing/viewing/' . $viewing->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('viewing/viewing/' . $viewing->getRouteKey()); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Remove the viewing. * * @param Model $viewing * * @return Response */ public function destroy(ViewingRequest $request, Viewing $viewing) { try { $viewing->delete(); $message = trans('messages.success.deleted', ['Module' => trans('viewing::viewing.name')]); $code = 202; $status = 'success'; $url = guard_url('viewing/viewing/0'); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('viewing/viewing/' . $viewing->getRouteKey()); } return compact('message', 'code', 'status', 'url'); } /** * Return the form elements as json. * * @param String $element * * @return json */ public function form($element = 'fields') { $form = new Form(); return $form->form($element, true); } }