repository = $propety; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\Marius\RealEstate1.0\Repositories\Criteria\PropetyResourceCriteria::class); } /** * Display a list of propety. * * @return Response */ public function index(PropetyRequest $request) { $view = $this->response->theme->listView(); if ($this->response->typeIs('json')) { $function = camel_case('get-' . $view); return $this->repository ->setPresenter(\Marius\RealEstate1.0\Repositories\Presenter\PropetyPresenter::class) ->$function(); } $propeties = $this->repository->paginate(); return $this->response->title(trans('real_estate1.0::propety.names')) ->view('real_estate1.0::propety.index', true) ->data(compact('propeties', 'view')) ->output(); } /** * Display propety. * * @param Request $request * @param Model $propety * * @return Response */ public function show(PropetyRequest $request, Propety $propety) { if ($propety->exists) { $view = 'real_estate1.0::propety.show'; } else { $view = 'real_estate1.0::propety.new'; } return $this->response->title(trans('app.view') . ' ' . trans('real_estate1.0::propety.name')) ->data(compact('propety')) ->view($view, true) ->output(); } /** * Show the form for creating a new propety. * * @param Request $request * * @return Response */ public function create(PropetyRequest $request) { $propety = $this->repository->newInstance([]); return $this->response->title(trans('app.new') . ' ' . trans('real_estate1.0::propety.name')) ->view('real_estate1.0::propety.create', true) ->data(compact('propety')) ->output(); } /** * Create new propety. * * @param Request $request * * @return Response */ public function store(PropetyRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id(); $attributes['user_type'] = user_type(); $propety = $this->repository->create($attributes); return $this->response->message(trans('messages.success.created', ['Module' => trans('real_estate1.0::propety.name')])) ->code(204) ->status('success') ->url(guard_url('real_estate1.0/propety/' . $propety->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/real_estate1.0/propety')) ->redirect(); } } /** * Show propety for editing. * * @param Request $request * @param Model $propety * * @return Response */ public function edit(PropetyRequest $request, Propety $propety) { return $this->response->title(trans('app.edit') . ' ' . trans('real_estate1.0::propety.name')) ->view('real_estate1.0::propety.edit', true) ->data(compact('propety')) ->output(); } /** * Update the propety. * * @param Request $request * @param Model $propety * * @return Response */ public function update(PropetyRequest $request, Propety $propety) { try { $attributes = $request->all(); $propety->update($attributes); return $this->response->message(trans('messages.success.updated', ['Module' => trans('real_estate1.0::propety.name')])) ->code(204) ->status('success') ->url(guard_url('real_estate1.0/propety/' . $propety->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('real_estate1.0/propety/' . $propety->getRouteKey())) ->redirect(); } } /** * Remove the propety. * * @param Model $propety * * @return Response */ public function destroy(PropetyRequest $request, Propety $propety) { try { $propety->delete(); return $this->response->message(trans('messages.success.deleted', ['Module' => trans('real_estate1.0::propety.name')])) ->code(202) ->status('success') ->url(guard_url('real_estate1.0/propety/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('real_estate1.0/propety/' . $propety->getRouteKey())) ->redirect(); } } /** * Remove multiple propety. * * @param Model $propety * * @return Response */ public function delete(PropetyRequest $request, $type) { try { $ids = hashids_decode($request->input('ids')); if ($type == 'purge') { $this->repository->purge($ids); } else { $this->repository->delete($ids); } return $this->response->message(trans('messages.success.deleted', ['Module' => trans('real_estate1.0::propety.name')])) ->status("success") ->code(202) ->url(guard_url('real_estate1.0/propety')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/real_estate1.0/propety')) ->redirect(); } } /** * Restore deleted propeties. * * @param Model $propety * * @return Response */ public function restore(PropetyRequest $request) { try { $ids = hashids_decode($request->input('ids')); $this->repository->restore($ids); return $this->response->message(trans('messages.success.restore', ['Module' => trans('real_estate1.0::propety.name')])) ->status("success") ->code(202) ->url(guard_url('/real_estate1.0/propety')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/real_estate1.0/propety/')) ->redirect(); } } }