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