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