Файловый менеджер - Редактировать - /home/clickysoft/public_html/somni.clickysoft.net/app/Http/Controllers/Admin/PropertyController.php
Назад
<?php namespace App\Http\Controllers\Admin; use App\Http\Controllers\Controller; use App\Http\Requests\MassDestroyPropertyRequest; use App\Http\Requests\StorePropertyRequest; use App\Http\Requests\UpdatePropertyRequest; use App\Models\Property; use App\Models\User; use Gate; use Illuminate\Http\Request; use Symfony\Component\HttpFoundation\Response; use Yajra\DataTables\Facades\DataTables; use App\Repositories\PropertyRepository; use App\Interfaces\PropertyRepositoryInterface; use App\Models\City; use App\Models\Country; use App\Models\State; class PropertyController extends Controller { private PropertyRepositoryInterface $propertyInterfaceObj; public function __construct(PropertyRepository $propertyRepo){ $this->propertyInterfaceObj = $propertyRepo; } public function index(Request $request) { abort_if(Gate::denies('property_access'), Response::HTTP_FORBIDDEN, '403 Forbidden'); if ($request->ajax()) { $query = Property::with(['user'])->select(sprintf('%s.*', (new Property)->table)); $table = Datatables::of($query); $table->addColumn('placeholder', ' '); $table->addColumn('actions', ' '); $table->editColumn('actions', function ($row) { $viewGate = 'property_show'; $editGate = 'property_edit'; $deleteGate = 'property_delete'; $crudRoutePart = 'properties'; return view('partials.datatablesActionsSlug', compact( 'viewGate', 'editGate', 'deleteGate', 'crudRoutePart', 'row' )); }); $table->editColumn('id', function ($row) { return $row->id ? $row->id : ''; }); $table->addColumn('user_name', function ($row) { return $row->user ? $row->user->name : ''; }); $table->editColumn('name', function ($row) { return $row->name ? $row->name : ''; }); $table->editColumn('address', function ($row) { return $row->address ? $row->address : ''; }); $table->editColumn('type', function ($row) { return $row->type ? Property::TYPE_SELECT[$row->type] : ''; }); $table->editColumn('country', function ($row) { return $row->country ? $row->country : ''; }); $table->editColumn('city', function ($row) { return $row->city ? $row->city : ''; }); $table->editColumn('state', function ($row) { return $row->state ? $row->state : ''; }); $table->editColumn('zip_code', function ($row) { return $row->zip_code ? $row->zip_code : ''; }); $table->editColumn('value', function ($row) { return $row->value ? '$'.$row->value : ''; }); $table->editColumn('purchase_term', function ($row) { return $row->purchase_term ? Property::PURCHASE_TERM_SELECT[$row->purchase_term] : ''; }); $table->rawColumns(['actions', 'placeholder', 'user']); return $table->make(true); } $users = User::get(); return view('admin.properties.index', compact('users')); } public function create() { abort_if(Gate::denies('property_create'), Response::HTTP_FORBIDDEN, '403 Forbidden'); $users = User::whereHas('roles',function($query){ $query->where('title','=','landlord'); })->pluck('name', 'id')->prepend(trans('global.pleaseSelect'), ''); // dd($users); return view('admin.properties.create', compact('users')); } public function store(StorePropertyRequest $request) { // dd($request->all()); $property = Property::create($request->all()); return redirect()->route('admin.properties.index'); } public function edit(Property $property) { abort_if(Gate::denies('property_edit'), Response::HTTP_FORBIDDEN, '403 Forbidden'); // $users = User::pluck('name', 'id')->prepend(trans('global.pleaseSelect'), ''); $users = User::whereHas('roles',function($query){ $query->where('title','=','landlord'); })->pluck('name', 'id')->prepend(trans('global.pleaseSelect'), ''); $property->load('user'); $country = Country::orderBy('name','asc')->get(); $state = State::orderBy('name','asc')->get(); $city = City::orderBy('name','asc')->get(); return view('admin.properties.edit', compact('property', 'users','country','state','city')); } public function update(UpdatePropertyRequest $request, Property $property) { $property->update($request->all()); return redirect()->route('admin.properties.index'); } public function show(Property $property) { abort_if(Gate::denies('property_show'), Response::HTTP_FORBIDDEN, '403 Forbidden'); $property->load('user', 'propertyUnits'); return view('admin.properties.show', compact('property')); } public function destroy(Property $property) { abort_if(Gate::denies('property_delete'), Response::HTTP_FORBIDDEN, '403 Forbidden'); $property->delete(); return back(); } public function massDestroy(MassDestroyPropertyRequest $request) { $properties = Property::find(request('ids')); foreach ($properties as $property) { $property->delete(); } return response(null, Response::HTTP_NO_CONTENT); } public function getStatesByCountryID($country_id){ $states = $this->propertyInterfaceObj->getStatesByCountry($country_id); return $states; } public function getCitiesByStateID($state_id){ $cities = $this->propertyInterfaceObj->getCititesByStates($state_id); return $cities; } }
| ver. 1.4 |
Github
|
.
| PHP 8.1.29 | Генерация страницы: 0.01 |
proxy
|
phpinfo
|
Настройка