2020-11-05 09:36:13 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Bo;
|
|
|
|
|
|
|
|
|
|
use App\Http\Controllers\Controller;
|
|
|
|
|
use App\Models\Content;
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
|
|
|
|
|
class ContentController extends Controller
|
|
|
|
|
{
|
2021-03-18 08:40:20 +01:00
|
|
|
public function manage(Request $request, $key)
|
|
|
|
|
{
|
2020-11-05 09:36:13 +01:00
|
|
|
$content = Content::where('key', $key)->first();
|
|
|
|
|
|
|
|
|
|
if ($_SERVER["REQUEST_METHOD"] === "POST") {
|
2022-08-25 12:26:43 +02:00
|
|
|
$banner = $request->banner;
|
|
|
|
|
$title = $request->title;
|
|
|
|
|
$chapeau = $request->chapeau;
|
2021-03-18 08:40:20 +01:00
|
|
|
$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;
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-25 12:26:43 +02:00
|
|
|
$content->title = $title;
|
2021-03-18 08:40:20 +01:00
|
|
|
$content->chapeau = $chapeau;
|
2022-08-25 12:26:43 +02:00
|
|
|
$content->value = $maintext;
|
2020-11-05 09:36:13 +01:00
|
|
|
$content->save();
|
|
|
|
|
|
2021-03-18 08:40:20 +01:00
|
|
|
return redirect()->route('bo.content', ['key' => $content->key, 'content' => $content])
|
|
|
|
|
->with('success', 'Modifications enregistrés !');
|
2022-08-25 12:26:43 +02:00
|
|
|
}//end if
|
2020-11-05 09:36:13 +01:00
|
|
|
|
|
|
|
|
return view('bo.content.manage', compact('content'));
|
|
|
|
|
}
|
|
|
|
|
}
|