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