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