ldc-boutique-cnc/app/Http/Controllers/Bo/ContentController.php
2022-08-25 12:26:43 +02:00

48 lines
1.7 KiB
PHP

<?php
namespace App\Http\Controllers\Bo;
use App\Http\Controllers\Controller;
use App\Models\Content;
use Illuminate\Http\Request;
class ContentController extends Controller
{
public function manage(Request $request, $key)
{
$content = Content::where('key', $key)->first();
if ($_SERVER["REQUEST_METHOD"] === "POST") {
$banner = $request->banner;
$title = $request->title;
$chapeau = $request->chapeau;
$maintext = $request->value;
$request->validate([
'banner' => 'image|mimes:jpeg,png,jpg|max:2048|dimensions:max_width=' .
config('theme.content_banner_maxwidth') .
',max_height=' . config('theme.content_banner_maxheight'),
'value' => 'required',
]);
if ($banner !== null) {
if ($content->banner !== null && file_exists(public_path('images/content/') . $content->banner)) {
unlink(public_path('images/content/') . $content->banner);
}
$imageName = $content->id . '.' . $banner->extension();
$banner->move(public_path('images/content'), $imageName);
$content->banner = $imageName;
}
$content->title = $title;
$content->chapeau = $chapeau;
$content->value = $maintext;
$content->save();
return redirect()->route('bo.content', ['key' => $content->key, 'content' => $content])
->with('success', 'Modifications enregistrés !');
}//end if
return view('bo.content.manage', compact('content'));
}
}