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