ldc-crm/app/Http/Controllers/BrandController.php
Jérémy Munsch 2e99623428 Normalize
- add phpcs
  - fix php standards
  - fix Laravel standards
  - normalize tables names
2021-03-01 06:57:45 +01:00

42 lines
976 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'));
}
}