form = PropertyForm::setAttributes()->toArray(); $this->modules = $this->modules(config('realestate.property.modules'), 'property', guard_url('property')); $this->repository = $property; } /** * Display a list of property. * * @return Response */ public function index(PropertyRequest $request) { $pageLimit = $request->input('pageLimit', config('database.pagination.limit')); $data = $this->repository ->pushFilter(RequestFilter::class) ->pushFilter(PropertyResourceFilter::class) ->setPresenter(PropertyListPresenter::class) ->simplePaginate($pageLimit) // ->withQueryString() ->toArray(); extract($data); $form = $this->form; $modules = $this->modules; return $this->response->setMetaTitle(trans('property::property.names')) ->view('property::property.index') ->data(compact('data', 'meta', 'links', 'modules', 'form')) ->output(); } /** * Display property. * * @param Request $request * @param Model $property * * @return Response */ public function show(PropertyRequest $request, PropertyRepositoryInterface $repository) { $form = $this->form; $modules = $this->modules; $data = $repository->toArray(); return $this->response ->setMetaTitle(trans('app.view') . ' ' . trans('property::property.name')) ->data(compact('data', 'form', 'modules', 'form')) ->view('property::property.show') ->output(); } /** * Show the form for creating a new property. * * @param Request $request *x * @return Response */ public function create(PropertyRequest $request, PropertyRepositoryInterface $repository) { $form = $this->form; $modules = $this->modules; $data = $repository->toArray(); return $this->response->setMetaTitle(trans('app.new') . ' ' . trans('property::property.name')) ->view('property::property.create') ->data(compact('data', 'form', 'modules')) ->output(); } /** * Create new property. * * @param Request $request * * @return Response */ public function store(PropertyRequest $request, PropertyRepositoryInterface $repository) { try { $attributes = $request->all(); $attributes['user_id'] = user_id(); $attributes['user_type'] = user_type(); $repository->create($attributes); $data = $repository->toArray(); return $this->response->message(trans('messages.success.created', ['Module' => trans('property::property.name')])) ->code(204) ->data(compact('data')) ->status('success') ->url(guard_url('property/property/' . $data['id'])) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/property/property')) ->redirect(); } } /** * Show property for editing. * * @param Request $request * @param Model $property * * @return Response */ public function edit(PropertyRequest $request, PropertyRepositoryInterface $repository) { $form = $this->form; $modules = $this->modules; $data = $repository->toArray(); return $this->response->setMetaTitle(trans('app.edit') . ' ' . trans('property::property.name')) ->view('property::property.edit') ->data(compact('data', 'form', 'modules')) ->output(); } /** * Update the property. * * @param Request $request * @param Model $property * * @return Response */ public function update(PropertyRequest $request, PropertyRepositoryInterface $repository) { try { $attributes = $request->all(); $repository->update($attributes); $data = $repository->toArray(); return $this->response->message(trans('messages.success.updated', ['Module' => trans('property::property.name')])) ->code(204) ->status('success') ->data(compact('data')) ->url(guard_url('property/property/' . $data['id'])) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('property/property/' . $repository->getRouteKey())) ->redirect(); } } /** * Remove the property. * * @param Model $property * * @return Response */ public function destroy(PropertyRequest $request, PropertyRepositoryInterface $repository) { try { $repository->delete(); $data = $repository->toArray(); return $this->response->message(trans('messages.success.deleted', ['Module' => trans('property::property.name')])) ->code(202) ->status('success') ->data(compact('data')) ->url(guard_url('property/property/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('property/property/' . $repository->getRouteKey())) ->redirect(); } } }