ldc-crm/app/Http/Controllers/BrandController.php

43 lines
976 B
PHP
Raw Normal View History

2020-12-01 17:02:10 +01:00
<?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()
{
2020-12-01 17:02:10 +01:00
$brands = Brand::all();
return view('brands.index', compact('brands'));
}
public function manage(Request $request, $id = null)
{
2020-12-01 17:02:10 +01:00
$brand = null;
if ($id !== null) {
2020-12-01 17:02:10 +01:00
$brand = Brand::find($id);
}
2020-12-01 17:02:10 +01:00
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'));
}
}