57 lines
1.5 KiB
PHP
57 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Bo;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Requests\UpdateMomentRequest;
|
|
use App\Lib\Utils;
|
|
use App\Models\Moment;
|
|
|
|
class MomentsController extends Controller
|
|
{
|
|
/**
|
|
* Display a listing of the resource.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function index()
|
|
{
|
|
$moments = Moment::orderBy('created_at', 'DESC')->get();
|
|
|
|
return view('back.moments.index', compact('moments'));
|
|
}
|
|
|
|
/**
|
|
* Show the form for editing the specified resource.
|
|
*
|
|
* @param Moment $moment
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function edit(Moment $moment)
|
|
{
|
|
return view('back.moments.edit', compact('moment'));
|
|
}
|
|
|
|
/**
|
|
* Update the specified resource in storage.
|
|
*
|
|
* @param Moment $moment
|
|
* @param \Illuminate\Http\UpdateMomentRequest $request
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function update(Moment $moment, UpdateMomentRequest $request)
|
|
{
|
|
$moment->fill($request->validated());
|
|
if (is_a($request->picture, "SplFileInfo")) {
|
|
$moment->picture = Utils::storeImage($request->picture, $moment->getTable());
|
|
}
|
|
|
|
if (!$moment->saveOrFail()) {
|
|
return redirect()->route('bo.moments.edit', $moment->id)
|
|
->with('error', trans('La modification a échoué'));
|
|
}
|
|
|
|
return redirect()->route('bo.moments.edit', $moment->id)
|
|
->with('success', trans('Modifications enregistrées !'));
|
|
}
|
|
}
|