109 lines
3.4 KiB
PHP
109 lines
3.4 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Bo;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Requests\StorePictoBrandRequest;
|
|
use App\Http\Requests\UpdatePictoBrandRequest;
|
|
use App\Lib\Utils;
|
|
use App\Models\PictoBrand;
|
|
|
|
class PictoBrandsController extends Controller
|
|
{
|
|
/**
|
|
* Display a listing of the resource.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function index()
|
|
{
|
|
$pictobrands = PictoBrand::all();
|
|
|
|
return view('back.pictobrands.index', compact('pictobrands'));
|
|
}
|
|
|
|
/**
|
|
* Show the form for creating a new resource.
|
|
*
|
|
* @param PictoBrand $pictobrand
|
|
* @return \Illuminate\Http\Response
|
|
*
|
|
* @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass
|
|
*/
|
|
public function create(PictoBrand $pictobrand)
|
|
{
|
|
return view('back.pictobrands.create', compact('pictobrand'));
|
|
}
|
|
|
|
/**
|
|
* Store a newly created resource in storage.
|
|
*
|
|
* @param \Illuminate\Http\StorePictoBrandRequest $request
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function store(StorePictoBrandRequest $request)
|
|
{
|
|
$pictobrand = new PictoBrand($request->validated());
|
|
if (is_a($request->picture, "SplFileInfo")) {
|
|
$pictobrand->picture = Utils::storeImage($request->picture, $pictobrand->getTable());
|
|
}
|
|
|
|
if (!$pictobrand->saveOrFail()) {
|
|
return redirect()->route('bo.pictobrands.edit', $pictobrand->id)
|
|
->with('error', 'Le pictogramme n\'a pas été crée');
|
|
}
|
|
return redirect()->route('bo.pictobrands.edit', $pictobrand->id)
|
|
->with('success', 'Pictogramme créé !');
|
|
}
|
|
|
|
/**
|
|
* Show the form for editing the specified resource.
|
|
*
|
|
* @param PictoBrand $pictobrand
|
|
* @return \Illuminate\Http\Response
|
|
*
|
|
* @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass
|
|
*/
|
|
public function edit(PictoBrand $pictobrand)
|
|
{
|
|
return view('back.pictobrands.edit', compact('pictobrand'));
|
|
}
|
|
|
|
/**
|
|
* Update the specified resource in storage.
|
|
*
|
|
* @param PictoBrand $pictobrand
|
|
* @param \Illuminate\Http\UpdatePictoBrandRequest $request
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function update(PictoBrand $pictobrand, UpdatePictoBrandRequest $request)
|
|
{
|
|
$pictobrand->fill($request->validated());
|
|
if (is_a($request->picture, "SplFileInfo")) {
|
|
$pictobrand->picture = Utils::storeImage($request->picture, $pictobrand->getTable());
|
|
}
|
|
|
|
if (!$pictobrand->saveOrFail()) {
|
|
return redirect()->route('bo.pictobrands.edit', $pictobrand->id)
|
|
->with('error', trans('La modification a échoué'));
|
|
}
|
|
|
|
return redirect()->route('bo.pictobrands.edit', $pictobrand->id)
|
|
->with('success', trans('Modifications enregistrées !'));
|
|
}
|
|
|
|
/**
|
|
* Remove the specified resource from storage.
|
|
*
|
|
* @param PictoBrand $pictobrand
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function destroy(PictoBrand $pictobrand)
|
|
{
|
|
if (!$pictobrand->delete()) {
|
|
return redirect()->route('bo.pictobrands.index')->with('error', trans('La suppression a échoué'));
|
|
}
|
|
|
|
return redirect()->route('bo.pictobrands.index')->with('success', trans('Suppression faite avec succès'));
|
|
}
|
|
}
|