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