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