repository = $estate; parent::__construct(); } /** * Display a list of estate. * * @return Response */ public function index(EstateAdminWebRequest $request) { if ($request->wantsJson()) { $estates = $this->repository->setPresenter('\\Fa\\Portal\\Repositories\\Presenter\\EstateListPresenter') ->scopeQuery(function($query){ return $query->orderBy('id','DESC'); })->all(); return response()->json($estates, 200); } $this ->theme->prependTitle(trans('portal::estate.names').' :: '); return $this->theme->of('portal::admin.estate.index')->render(); } /** * Display estate. * * @param Request $request * @param Model $estate * * @return Response */ public function show(EstateAdminWebRequest $request, Estate $estate) { if (!$estate->exists) { return response()->view('portal::admin.estate.new', compact('estate')); } Form::populate($estate); return response()->view('portal::admin.estate.show', compact('estate')); } /** * Show the form for creating a new estate. * * @param Request $request * * @return Response */ public function create(EstateAdminWebRequest $request) { $estate = $this->repository->newInstance([]); Form::populate($estate); return response()->view('portal::admin.estate.create', compact('estate')); } /** * Create new estate. * * @param Request $request * * @return Response */ public function store(EstateAdminWebRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id('admin.web'); $estate = $this->repository->create($attributes); return response()->json([ 'message' => trans('messages.success.updated', ['Module' => trans('portal::estate.name')]), 'code' => 204, 'redirect' => trans_url('/admin/portal/estate/'.$estate->getRouteKey()) ], 201); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 400, ], 400); } } /** * Show estate for editing. * * @param Request $request * @param Model $estate * * @return Response */ public function edit(EstateAdminWebRequest $request, Estate $estate) { Form::populate($estate); return response()->view('portal::admin.estate.edit', compact('estate')); } /** * Update the estate. * * @param Request $request * @param Model $estate * * @return Response */ public function update(EstateAdminWebRequest $request, Estate $estate) { try { $attributes = $request->all(); $estate->update($attributes); return response()->json([ 'message' => trans('messages.success.updated', ['Module' => trans('portal::estate.name')]), 'code' => 204, 'redirect' => trans_url('/admin/portal/estate/'.$estate->getRouteKey()) ], 201); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 400, 'redirect' => trans_url('/admin/portal/estate/'.$estate->getRouteKey()), ], 400); } } /** * Remove the estate. * * @param Model $estate * * @return Response */ public function destroy(EstateAdminWebRequest $request, Estate $estate) { try { $t = $estate->delete(); return response()->json([ 'message' => trans('messages.success.deleted', ['Module' => trans('portal::estate.name')]), 'code' => 202, 'redirect' => trans_url('/admin/portal/estate/0'), ], 202); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 400, 'redirect' => trans_url('/admin/portal/estate/'.$estate->getRouteKey()), ], 400); } } }