2024-01-10 15:10:21 +04:00
|
|
|
<?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;
|
2024-01-10 15:10:21 +04:00
|
|
|
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
|
2024-01-10 15:10:21 +04:00
|
|
|
){
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display a listing of the resource.
|
|
|
|
*/
|
2024-01-18 16:41:28 +04:00
|
|
|
public function index(): View
|
2024-01-10 15:10:21 +04:00
|
|
|
{
|
|
|
|
return view('deliveries.index', [
|
2024-01-18 16:41:28 +04:00
|
|
|
'deliveries' => $this->deliveryRepository->getAllDeliveries()
|
2024-01-10 15:10:21 +04:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the form for creating a new resource.
|
|
|
|
*/
|
2024-01-18 16:41:28 +04:00
|
|
|
public function create(): View
|
2024-01-10 15:10:21 +04:00
|
|
|
{
|
2024-01-18 16:41:28 +04:00
|
|
|
$this->authorize('create', Delivery::class);
|
|
|
|
|
|
|
|
return view('deliveries.create');
|
2024-01-10 15:10:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Store a newly created resource in storage.
|
|
|
|
*/
|
2024-01-18 16:41:28 +04:00
|
|
|
public function store(DeliveryPostRequest $request): RedirectResponse
|
2024-01-10 15:10:21 +04:00
|
|
|
{
|
2024-01-18 16:41:28 +04:00
|
|
|
$this->authorize('create', Delivery::class);
|
2024-01-10 15:10:21 +04:00
|
|
|
$this->deliveryRepository->createDelivery($request->validated());
|
|
|
|
|
|
|
|
return redirect()->route('deliveries.index');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display the specified resource.
|
|
|
|
*/
|
|
|
|
public function show(Delivery $delivery): View
|
|
|
|
{
|
2024-01-18 16:41:28 +04:00
|
|
|
$this->authorize('view', $delivery);
|
|
|
|
|
2024-01-10 15:10:21 +04:00
|
|
|
return view('deliveries.show', [
|
|
|
|
'delivery' => $delivery,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the form for editing the specified resource.
|
|
|
|
*/
|
2024-01-18 16:41:28 +04:00
|
|
|
public function edit(Delivery $delivery): View
|
2024-01-10 15:10:21 +04:00
|
|
|
{
|
2024-01-18 16:41:28 +04:00
|
|
|
$this->authorize('update', $delivery);
|
|
|
|
|
2024-01-10 15:10:21 +04:00
|
|
|
return view('deliveries.edit', [
|
|
|
|
'delivery' => $delivery,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the specified resource in storage.
|
|
|
|
*/
|
|
|
|
public function update(DeliveryPostRequest $request, Delivery $delivery): RedirectResponse
|
|
|
|
{
|
2024-01-18 16:41:28 +04:00
|
|
|
$this->authorize('update', $delivery);
|
2024-01-10 15:10:21 +04:00
|
|
|
$this->deliveryRepository->updateDelivery($delivery, $request->validated());
|
|
|
|
|
|
|
|
return redirect()->route('deliveries.index');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove the specified resource from storage.
|
|
|
|
*/
|
|
|
|
public function destroy(Delivery $delivery): RedirectResponse
|
|
|
|
{
|
2024-01-18 16:41:28 +04:00
|
|
|
$this->authorize('delete', $delivery);
|
2024-01-10 15:10:21 +04:00
|
|
|
$this->deliveryRepository->deleteDelivery($delivery);
|
|
|
|
|
|
|
|
return redirect()->route('deliveries.index');
|
|
|
|
}
|
|
|
|
}
|