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