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