47 lines
1.4 KiB
PHP
47 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Bo;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Requests\UpdateEncartRequest;
|
|
use App\Lib\Utils;
|
|
use App\Models\Encart;
|
|
|
|
class EncartsController extends Controller
|
|
{
|
|
/**
|
|
* Show the form for editing the specified resource.
|
|
*
|
|
* @param Encart $encart
|
|
* @return \Illuminate\Http\Response
|
|
*
|
|
* @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass
|
|
*/
|
|
public function edit(Encart $encart)
|
|
{
|
|
return view('back.encarts.edit', compact('encart'));
|
|
}
|
|
|
|
/**
|
|
* Update the specified resource in storage.
|
|
*
|
|
* @param Encart $encart
|
|
* @param \Illuminate\Http\UpdateEncartRequest $request
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function update(Encart $encart, UpdateEncartRequest $request)
|
|
{
|
|
$encart->fill($request->validated());
|
|
if (is_a($request->picture, "SplFileInfo")) {
|
|
$encart->picture = Utils::storeImage($request->picture, $encart->getTable());
|
|
}
|
|
|
|
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 !'));
|
|
}
|
|
}
|