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

32 lines
814 B
PHP
Raw Normal View History

2020-12-01 17:02:10 +01:00
<?php
namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
2021-03-14 10:45:42 +01:00
use App\Http\Requests\ManageBrandRequest;
2020-12-01 17:02:10 +01:00
use App\Models\Brand;
class BrandController extends Controller
{
public function index()
{
2020-12-01 17:02:10 +01:00
$brands = Brand::all();
return view('brands.index', compact('brands'));
}
2021-03-14 10:45:42 +01:00
public function manage(ManageBrandRequest $request, Brand $brand)
{
2021-03-14 10:45:42 +01:00
if ($request->isMethod('post')) {
2020-12-01 17:02:10 +01:00
if (!$brand) {
2021-03-14 10:45:42 +01:00
$brand = new Brand($request->validated());
} else {
$brand->fill($request->validated());
2020-12-01 17:02:10 +01:00
}
$brand->save();
2021-03-14 10:45:42 +01:00
return redirect()->route('brands')->with('success', trans('Modifications enregistrées !'));
2020-12-01 17:02:10 +01:00
}
return view('brands.manage', compact('brand'));
}
}