repository = $employees; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\Bixo\Employee\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(\Bixo\Employee\Repositories\Presenter\EmployeesPresenter::class) ->$function(); } $employees = $this->repository->paginate(); return $this->response->setMetaTitle(trans('employee::employees.names')) ->view('employee::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 = 'employee::employees.show'; } else { $view = 'employee::employees.new'; } return $this->response->setMetaTitle(trans('app.view') . ' ' . trans('employee::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('employee::employees.name')) ->view('employee::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('employee::employees.name')])) ->code(204) ->status('success') ->url(guard_url('employee/employees/' . $employees->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/employee/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('employee::employees.name')) ->view('employee::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('employee::employees.name')])) ->code(204) ->status('success') ->url(guard_url('employee/employees/' . $employees->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('employee/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('employee::employees.name')])) ->code(202) ->status('success') ->url(guard_url('employee/employees/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('employee/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('employee::employees.name')])) ->status("success") ->code(202) ->url(guard_url('employee/employees')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/employee/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('employee::employees.name')])) ->status("success") ->code(202) ->url(guard_url('/employee/employees')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/employee/employees/')) ->redirect(); } } }