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