/
Shamaeva2
/
coursework.local
Обзор
Документация
Войти
/
Shamaeva2
/
coursework.local
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
app/Http/Controllers/DutyPlaceController.php
126 строк
3 KB
Шамаева Виктория Сергеевна
crud для учебной группы
24 июн 2026, 10:17
24 июн 2026, 10:17
8499af3
Код
Авторство
О чём код?
<?php namespace App\Http\Controllers; use App\Models\DutyPlace; use App\Http\Requests\StoreDutyPlaceRequest; use App\Http\Requests\UpdateDutyPlaceRequest; use App\Models\Building; use Illuminate\Http\Request; use Illuminate\Support\Facades\Gate; use Inertia\Response; use Inertia\Inertia; class DutyPlaceController extends Controller { /** * Display a listing of the resource. */ public function index(Request $request): Response { Gate::authorize('viewAny', DutyPlace::class); $perPage = 10; $orderBy = (string) $request->input('orderBy', 'desc'); $search = (string) $request->input('search', ''); $query = DutyPlace::query(); match ($orderBy) { 'desc' => $query->orderBy('created_at', 'desc'), 'asc' => $query->orderBy('created_at', 'asc'), default => $query->orderBy('created_at', 'desc'), }; if ($request->filled('search')) { $query->where(function ($searchQuery) use ($search) { $searchQuery->where('name', 'LIKE', "%{$search}%") ->orWhere('description', 'LIKE', "%{$search}%"); }); } $dutyPlaces = $query->paginate($perPage)->withQueryString(); return Inertia::render('dutyPlace/VIndex', [ 'dutyPlaces' => $dutyPlaces, 'filters' => [ 'orderBy' => $orderBy, 'search' => $search, ], ]); } /** * Show the form for creating a new resource. */ public function create() { Gate::authorize('create', DutyPlace::class); $buildings = Building::all(); return Inertia::render('dutyPlace/VCreate', [ 'buildings' => $buildings, ]); } /** * Store a newly created resource in storage. */ public function store(StoreDutyPlaceRequest $request) { Gate::authorize('create', DutyPlace::class); DutyPlace::create($request->validated()); return redirect()->route('dutyPlaces.index'); } /** * Display the specified resource. */ public function show(DutyPlace $dutyPlace) { Gate::authorize('view', $dutyPlace); return Inertia::render('dutyPlace/VShow', [ 'dutyPlace' => $dutyPlace, ]); } /** * Show the form for editing the specified resource. */ public function edit(DutyPlace $dutyPlace) { Gate::authorize('update', $dutyPlace); $buildings = Building::all(); return Inertia::render('dutyPlace/VEdit', [ 'dutyPlace' => $dutyPlace, 'buildings' => $buildings, ]); } /** * Update the specified resource in storage. */ public function update(UpdateDutyPlaceRequest $request, DutyPlace $dutyPlace) { Gate::authorize('update', $dutyPlace); $dutyPlace->update($request->validated()); return redirect()->route('dutyPlaces.index'); } /** * Remove the specified resource from storage. */ public function destroy(DutyPlace $dutyPlace) { Gate::authorize('delete', $dutyPlace); $dutyPlace->delete(); return redirect()->route('dutyPlaces.index'); } }