40 lines
956 B
PHP
40 lines
956 B
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Http\Controllers;
|
||
|
|
|
||
|
|
use App\Http\Controllers\Controller;
|
||
|
|
use App\Models\Brand;
|
||
|
|
use Illuminate\Http\Request;
|
||
|
|
|
||
|
|
class BrandController extends Controller
|
||
|
|
{
|
||
|
|
public function index() {
|
||
|
|
$brands = Brand::all();
|
||
|
|
return view('brands.index', compact('brands'));
|
||
|
|
}
|
||
|
|
|
||
|
|
public function manage(Request $request, $id = null) {
|
||
|
|
$brand = null;
|
||
|
|
|
||
|
|
if ($id !== null)
|
||
|
|
$brand = Brand::find($id);
|
||
|
|
|
||
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||
|
|
$request->validate([
|
||
|
|
'name' => 'required|max:255',
|
||
|
|
]);
|
||
|
|
|
||
|
|
if (!$brand) {
|
||
|
|
$brand = new Brand();
|
||
|
|
}
|
||
|
|
|
||
|
|
$brand->name = filter_var($request->name, FILTER_SANITIZE_STRING);
|
||
|
|
$brand->save();
|
||
|
|
|
||
|
|
return redirect()->route('brands')->with('success', 'Modifications enregistrées !');
|
||
|
|
}
|
||
|
|
|
||
|
|
return view('brands.manage', compact('brand'));
|
||
|
|
}
|
||
|
|
}
|