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