SUBD_Transport_Company/app/Http/Controllers/DeliveryController.php

97 lines
2.4 KiB
PHP
Raw Normal View History

<?php
namespace App\Http\Controllers;
use App\Http\Requests\DeliveryPostRequest;
use App\Models\Delivery;
2024-01-16 15:14:13 +04:00
use App\Models\User;
use App\Repositories\Interfaces\DeliveryRepositoryInterface;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\View\View;
class DeliveryController extends Controller
{
public function __construct(
2024-01-16 15:14:13 +04:00
private readonly DeliveryRepositoryInterface $deliveryRepository
){
}
/**
* Display a listing of the resource.
*/
public function index(): View
{
return view('deliveries.index', [
'deliveries' => $this->deliveryRepository->getAllDeliveries()
]);
}
/**
* Show the form for creating a new resource.
*/
public function create(): View
{
$this->authorize('create', Delivery::class);
return view('deliveries.create');
}
/**
* Store a newly created resource in storage.
*/
public function store(DeliveryPostRequest $request): RedirectResponse
{
$this->authorize('create', Delivery::class);
$this->deliveryRepository->createDelivery($request->validated());
return redirect()->route('deliveries.index');
}
/**
* Display the specified resource.
*/
public function show(Delivery $delivery): View
{
$this->authorize('view', $delivery);
return view('deliveries.show', [
'delivery' => $delivery,
]);
}
/**
* Show the form for editing the specified resource.
*/
public function edit(Delivery $delivery): View
{
$this->authorize('update', $delivery);
return view('deliveries.edit', [
'delivery' => $delivery,
]);
}
/**
* Update the specified resource in storage.
*/
public function update(DeliveryPostRequest $request, Delivery $delivery): RedirectResponse
{
$this->authorize('update', $delivery);
$this->deliveryRepository->updateDelivery($delivery, $request->validated());
return redirect()->route('deliveries.index');
}
/**
* Remove the specified resource from storage.
*/
public function destroy(Delivery $delivery): RedirectResponse
{
$this->authorize('delete', $delivery);
$this->deliveryRepository->deleteDelivery($delivery);
return redirect()->route('deliveries.index');
}
}