90 lines
2.3 KiB
PHP
90 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Bo;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Requests\Bo\Brands\StoreBrandRequest;
|
|
use App\Http\Requests\Bo\Brands\UpdateBrandRequest;
|
|
use App\Models\Brand;
|
|
use Illuminate\Http\Request;
|
|
|
|
class BrandController extends Controller
|
|
{
|
|
/**
|
|
* Display a listing of the resource.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function index()
|
|
{
|
|
return view('bo.pages.brands.list', [
|
|
'brands' => Brand::query()->paginate(10)
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Show the form for creating a new resource.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function create()
|
|
{
|
|
return view('bo.pages.brands.create');
|
|
}
|
|
|
|
/**
|
|
* Store a newly created resource in storage.
|
|
*
|
|
* @param StoreBrandRequest $request
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function store(StoreBrandRequest $request)
|
|
{
|
|
$newBrand = new Brand();
|
|
$newBrand->fill($request->validated());
|
|
$newBrand->saveOrFail();
|
|
return redirect()->route('bo.brands.index')
|
|
->with(['success' => 'La marque ' . $newBrand->name . ' a bien été créée.']);
|
|
}
|
|
|
|
/**
|
|
* Show the form for editing the specified resource.
|
|
*
|
|
* @param Brand $brand
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function edit(Brand $brand)
|
|
{
|
|
return view('bo.pages.brands.edit', [
|
|
'brand' => $brand
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Update the specified resource in storage.
|
|
*
|
|
* @param UpdateBrandRequest $request
|
|
* @param Brand $brand
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function update(UpdateBrandRequest $request, Brand $brand)
|
|
{
|
|
$brand->fill($request->validated());
|
|
$brand->saveOrFail();
|
|
return redirect()->route('bo.brands.index')
|
|
->with(['success' => 'La marque ' . $brand->name . ' a bien été modifiée.']);
|
|
}
|
|
|
|
/**
|
|
* Remove the specified resource from storage.
|
|
*
|
|
* @param Brand $brand
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function destroy(Brand $brand)
|
|
{
|
|
$brand->deleteOrFail();
|
|
return redirect()->route('bo.brands.index')
|
|
->with(['warning' => 'La marque ' . $brand->name . ' a bien été supprimée.']);
|
|
}
|
|
}
|