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