repository = $employee; $this->repository ->pushCriteria(app('Litepie\Repository\Criteria\RequestCriteria')) ->pushCriteria(new \Payroll\Employee\Repositories\Criteria\EmployeeUserCriteria()); parent::__construct(); } /** * Display a listing of the resource. * * @return Response */ public function index(EmployeeRequest $request) { $employees = $this->repository->scopeQuery(function($query){ return $query->orderBy('id','DESC'); })->paginate(); $this->theme->prependTitle(trans('employee::employee.names')); return $this->theme->of('employee::user.employee.index', compact('employees'))->render(); } /** * Display the specified resource. * * @param Request $request * @param Employee $employee * * @return Response */ public function show(EmployeeRequest $request, Employee $employee) { Form::populate($employee); return $this->theme->of('employee::user.employee.show', compact('employee'))->render(); } /** * Show the form for creating a new resource. * * @param Request $request * * @return Response */ public function create(EmployeeRequest $request) { $employee = $this->repository->newInstance([]); Form::populate($employee); $this->theme->prependTitle(trans('employee::employee.names')); return $this->theme->of('employee::user.employee.create', compact('employee'))->render(); } /** * Display the specified resource. * * @param Request $request * * @return Response */ public function store(EmployeeRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id(); $employee = $this->repository->create($attributes); return redirect(trans_url('/user/employee/employee')) -> with('message', trans('messages.success.created', ['Module' => trans('employee::employee.name')])) -> with('code', 201); } catch (Exception $e) { redirect()->back()->withInput()->with('message', $e->getMessage())->with('code', 400); } } /** * Show the form for editing the specified resource. * * @param Request $request * @param Employee $employee * * @return Response */ public function edit(EmployeeRequest $request, Employee $employee) { Form::populate($employee); $this->theme->prependTitle(trans('employee::employee.names')); return $this->theme->of('employee::user.employee.edit', compact('employee'))->render(); } /** * Update the specified resource. * * @param Request $request * @param Employee $employee * * @return Response */ public function update(EmployeeRequest $request, Employee $employee) { try { $this->repository->update($request->all(), $employee->getRouteKey()); return redirect(trans_url('/user/employee/employee')) ->with('message', trans('messages.success.updated', ['Module' => trans('employee::employee.name')])) ->with('code', 204); } catch (Exception $e) { redirect()->back()->withInput()->with('message', $e->getMessage())->with('code', 400); } } /** * Remove the specified resource. * * @param int $id * * @return Response */ public function destroy(EmployeeRequest $request, Employee $employee) { try { $this->repository->delete($employee->getRouteKey()); return redirect(trans_url('/user/employee/employee')) ->with('message', trans('messages.success.deleted', ['Module' => trans('employee::employee.name')])) ->with('code', 204); } catch (Exception $e) { redirect()->back()->withInput()->with('message', $e->getMessage())->with('code', 400); } } }