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