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