middleware(function ($request, $next) { $this->form = EmployeeForm::grouped(false) ->setAttributes() ->toArray(); $this->modules = $this->modules(config('bixo.employee.modules'), 'employee', guard_url('employee')); return $next($request); }); } /** * Display a list of employee. * * @return Response */ public function index(EmployeeResourceRequest $request) { $request = $request->all(); $page = EmployeeActions::run('paginate', $request); $data = new EmployeesCollection($page); $form = $this->form; $modules = $this->modules; return $this->response->setMetaTitle(trans('employee::employee.names')) ->view('employee::employee.index') ->data(compact('data', 'modules', 'form')) ->output(); } /** * Display employee. * * @param Request $request * @param Model $employee * * @return Response */ public function show(EmployeeResourceRequest $request, Employee $model) { $form = $this->form; $modules = $this->modules; $data = new EmployeeResource($model); return $this->response ->setMetaTitle(trans('app.view') . ' ' . trans('employee::employee.name')) ->data(compact('data', 'form', 'modules')) ->view('employee::employee.show') ->output(); } /** * Show the form for creating a new employee. * * @param Request $request * * @return Response */ public function create(EmployeeResourceRequest $request, Employee $model) { $form = $this->form; $modules = $this->modules; $data = new EmployeeResource($model); return $this->response->setMetaTitle(trans('app.new') . ' ' . trans('employee::employee.name')) ->view('employee::employee.create') ->data(compact('data', 'form', 'modules')) ->output(); } /** * Create new employee. * * @param Request $request * * @return Response */ public function store(EmployeeResourceRequest $request, Employee $model) { try { $request = $request->all(); $model = EmployeeAction::run('store', $model, $request); $data = new EmployeeResource($model); return $this->response->message(trans('messages.success.created', ['Module' => trans('employee::employee.name')])) ->code(204) ->data(compact('data')) ->status('success') ->url(guard_url('employee/employee/' . $model->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(EmployeeResourceRequest $request, Employee $model) { $form = $this->form; $modules = $this->modules; $data = new EmployeeResource($model); // return view('employee::employee.edit', compact('data', 'form', 'modules')); return $this->response->setMetaTitle(trans('app.edit') . ' ' . trans('employee::employee.name')) ->view('employee::employee.edit') ->data(compact('data', 'form', 'modules')) ->output(); } /** * Update the employee. * * @param Request $request * @param Model $employee * * @return Response */ public function update(EmployeeResourceRequest $request, Employee $model) { try { $request = $request->all(); $model = EmployeeAction::run('update', $model, $request); $data = new EmployeeResource($model); return $this->response->message(trans('messages.success.updated', ['Module' => trans('employee::employee.name')])) ->code(204) ->status('success') ->data(compact('data')) ->url(guard_url('employee/employee/' . $model->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('employee/employee/' . $model->getRouteKey())) ->redirect(); } } /** * Remove the employee. * * @param Model $employee * * @return Response */ public function destroy(EmployeeResourceRequest $request, Employee $model) { try { $request = $request->all(); $model = EmployeeAction::run('destroy', $model, $request); $data = new EmployeeResource($model); return $this->response->message(trans('messages.success.deleted', ['Module' => trans('employee::employee.name')])) ->code(202) ->status('success') ->data(compact('data')) ->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/' . $model->getRouteKey())) ->redirect(); } } }