ldc-doux/app/Http/Controllers/Bo/PictoBrandsController.php

110 lines
3.4 KiB
PHP
Raw Normal View History

2021-12-13 16:55:12 +01:00
<?php
namespace App\Http\Controllers\Bo;
use App\Http\Controllers\Controller;
2021-12-15 10:09:39 +01:00
use App\Http\Requests\StorePictoBrandRequest;
2021-12-13 16:55:12 +01:00
use App\Http\Requests\UpdatePictoBrandRequest;
2022-01-23 11:45:06 +01:00
use App\Lib\Utils;
2021-12-13 16:55:12 +01:00
use App\Models\PictoBrand;
class PictoBrandsController extends Controller
{
2021-12-15 10:09:39 +01:00
/**
* 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.
*
2022-08-29 17:23:10 +02:00
* @param PictoBrand $pictobrand
2021-12-15 10:09:39 +01:00
* @return \Illuminate\Http\Response
2022-08-29 17:23:10 +02:00
*
* @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass
2021-12-15 10:09:39 +01:00
*/
public function create(PictoBrand $pictobrand)
{
return view('back.pictobrands.create', compact('pictobrand'));
}
/**
* Store a newly created resource in storage.
*
2022-08-11 12:34:27 +02:00
* @param \Illuminate\Http\StorePictoBrandRequest $request
2021-12-15 10:09:39 +01:00
* @return \Illuminate\Http\Response
*/
public function store(StorePictoBrandRequest $request)
{
$pictobrand = new PictoBrand($request->validated());
2022-07-27 14:33:56 +02:00
if (is_a($request->picture, "SplFileInfo")) {
2022-01-23 11:45:06 +01:00
$pictobrand->picture = Utils::storeImage($request->picture, $pictobrand->getTable());
}
2021-12-15 10:09:39 +01:00
if (!$pictobrand->saveOrFail()) {
return redirect()->route('bo.pictobrands.edit', $pictobrand->id)
->with('error', 'Le pictogramme n\'a pas été crée');
2021-12-15 10:09:39 +01:00
}
return redirect()->route('bo.pictobrands.edit', $pictobrand->id)
->with('success', 'Pictogramme créé !');
2021-12-15 10:09:39 +01:00
}
2021-12-13 16:55:12 +01:00
/**
* Show the form for editing the specified resource.
*
2022-08-29 17:23:10 +02:00
* @param PictoBrand $pictobrand
2021-12-13 16:55:12 +01:00
* @return \Illuminate\Http\Response
2022-08-29 17:23:10 +02:00
*
* @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass
2021-12-13 16:55:12 +01:00
*/
public function edit(PictoBrand $pictobrand)
{
return view('back.pictobrands.edit', compact('pictobrand'));
}
/**
* Update the specified resource in storage.
*
2022-08-11 12:34:27 +02:00
* @param PictoBrand $pictobrand
* @param \Illuminate\Http\UpdatePictoBrandRequest $request
2021-12-13 16:55:12 +01:00
* @return \Illuminate\Http\Response
*/
2022-07-18 10:36:38 +00:00
public function update(PictoBrand $pictobrand, UpdatePictoBrandRequest $request)
2021-12-13 16:55:12 +01:00
{
$pictobrand->fill($request->validated());
2022-07-27 14:33:56 +02:00
if (is_a($request->picture, "SplFileInfo")) {
2022-01-23 11:45:06 +01:00
$pictobrand->picture = Utils::storeImage($request->picture, $pictobrand->getTable());
}
2021-12-13 16:55:12 +01:00
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 !'));
}
2021-12-15 10:09:39 +01:00
/**
* Remove the specified resource from storage.
*
2022-08-11 12:34:27 +02:00
* @param PictoBrand $pictobrand
2021-12-15 10:09:39 +01:00
* @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'));
}
2021-12-13 16:55:12 +01:00
}