86 lines
1.8 KiB
PHP
86 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Http\Requests\CarPostRequest;
|
|
use App\Models\Car;
|
|
use App\Repositories\Interfaces\CarRepositoryInterface;
|
|
use Illuminate\Http\RedirectResponse;
|
|
use Illuminate\View\View;
|
|
|
|
class CarController extends Controller
|
|
{
|
|
public function __construct(
|
|
private CarRepositoryInterface $carRepository
|
|
){
|
|
}
|
|
|
|
/**
|
|
* Display a listing of the resource.
|
|
*/
|
|
public function index(): View
|
|
{
|
|
return view('cars.index', [
|
|
'cars' => $this->carRepository->getAllCars(),
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Show the form for creating a new resource.
|
|
*/
|
|
public function create(): View
|
|
{
|
|
return view('cars.create');
|
|
}
|
|
|
|
/**
|
|
* Store a newly created resource in storage.
|
|
*/
|
|
public function store(CarPostRequest $request): RedirectResponse
|
|
{
|
|
$this->carRepository->createCar($request->validated());
|
|
|
|
return redirect()->route('cars.index');
|
|
}
|
|
|
|
/**
|
|
* Display the specified resource.
|
|
*/
|
|
public function show(Car $car): View
|
|
{
|
|
return view('cars.show', [
|
|
'car' => $car,
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Show the form for editing the specified resource.
|
|
*/
|
|
public function edit(Car $car): View
|
|
{
|
|
return view('cars.edit', [
|
|
'car' => $car,
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Update the specified resource in storage.
|
|
*/
|
|
public function update(CarPostRequest $request, Car $car): RedirectResponse
|
|
{
|
|
$this->carRepository->updateCar($car, $request->validated());
|
|
|
|
return redirect()->route('cars.index');
|
|
}
|
|
|
|
/**
|
|
* Remove the specified resource from storage.
|
|
*/
|
|
public function destroy(Car $car): RedirectResponse
|
|
{
|
|
$this->carRepository->deleteCar($car);
|
|
|
|
return redirect()->route('cars.index');
|
|
}
|
|
}
|