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