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

48 lines
1.4 KiB
PHP
Raw Normal View History

2021-12-08 17:32:56 +01:00
<?php
2021-12-09 17:31:10 +01:00
namespace App\Http\Controllers\Bo;
2021-12-08 17:32:56 +01:00
2021-12-09 17:31:10 +01:00
use App\Http\Controllers\Controller;
use App\Http\Requests\UpdateEncartRequest;
use App\Lib\Utils;
2021-12-09 17:31:10 +01:00
use App\Models\Encart;
2021-12-08 17:32:56 +01:00
class EncartsController extends Controller
{
2021-12-09 17:31:10 +01:00
/**
* Show the form for editing the specified resource.
*
2022-08-29 17:23:10 +02:00
* @param Encart $encart
2021-12-09 17:31:10 +01:00
* @return \Illuminate\Http\Response
2022-08-29 17:23:10 +02:00
*
* @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass
2021-12-09 17:31:10 +01:00
*/
public function edit(Encart $encart)
{
2021-12-13 16:55:12 +01:00
return view('back.encarts.edit', compact('encart'));
2021-12-09 17:31:10 +01:00
}
/**
* Update the specified resource in storage.
*
2022-08-11 12:34:27 +02:00
* @param Encart $encart
* @param \Illuminate\Http\UpdateEncartRequest $request
2021-12-09 17:31:10 +01:00
* @return \Illuminate\Http\Response
*/
public function update(Encart $encart, UpdateEncartRequest $request)
{
$encart->fill($request->validated());
2022-07-27 14:33:56 +02:00
if (is_a($request->picture, "SplFileInfo")) {
$encart->picture = Utils::storeImage($request->picture, $encart->getTable());
}
2021-12-09 17:31:10 +01:00
if (!$encart->saveOrFail()) {
return redirect()->route('bo.encarts.edit', $encart->id)
->with('error', trans('La modification a échoué'));
}
return redirect()->route('bo.encarts.edit', $encart->id)
->with('success', trans('Modifications enregistrées !'));
}
2021-12-08 17:32:56 +01:00
}