2026-09-24 16:16:23 +02:00
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Bo;
|
|
|
|
|
|
|
|
|
|
|
|
use App\Http\Controllers\Controller;
|
|
|
|
|
|
use App\Models\GeneralConfig;
|
|
|
|
|
|
use Illuminate\Http\RedirectResponse;
|
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
|
|
|
use Illuminate\View\View;
|
|
|
|
|
|
|
|
|
|
|
|
class GeneralConfigController extends Controller
|
|
|
|
|
|
{
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Display the general configuration edit form.
|
|
|
|
|
|
*
|
|
|
|
|
|
* @return View
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function edit(): View
|
|
|
|
|
|
{
|
|
|
|
|
|
return view('bo.general-config.edit', [
|
|
|
|
|
|
'config' => GeneralConfig::current(),
|
|
|
|
|
|
]);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Upload and store the "Nos métiers" page image.
|
|
|
|
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param Request $request
|
|
|
|
|
|
* @return RedirectResponse
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function upload(Request $request): RedirectResponse
|
|
|
|
|
|
{
|
2026-09-24 16:41:59 +02:00
|
|
|
|
$config = GeneralConfig::current();
|
|
|
|
|
|
$ancienne = $config->get('image');
|
|
|
|
|
|
|
2026-09-24 16:16:23 +02:00
|
|
|
|
$request->validate(
|
2026-09-24 16:41:59 +02:00
|
|
|
|
[
|
|
|
|
|
|
'image' => [$ancienne ? 'nullable' : 'required', 'image', 'mimes:jpeg,png,jpg', 'max:2048', 'dimensions:width=742,height=464'],
|
|
|
|
|
|
'image_alt' => ['required', 'string', 'min:5','max:50'],
|
|
|
|
|
|
'image_title' => ['required', 'string', 'min:5','max:50'],
|
|
|
|
|
|
],
|
2026-09-24 16:16:23 +02:00
|
|
|
|
['image.dimensions' => "L'image doit faire exactement 742 × 464 px."]
|
|
|
|
|
|
);
|
|
|
|
|
|
|
2026-09-24 16:41:59 +02:00
|
|
|
|
if ($request->hasFile('image')) {
|
|
|
|
|
|
$photo = $request->file('image');
|
|
|
|
|
|
$imageName = 'image-' . now()->format('YmdHis') . '.' . $photo->extension();
|
2026-09-24 16:16:23 +02:00
|
|
|
|
|
2026-09-24 16:41:59 +02:00
|
|
|
|
$path = $photo->storeAs(
|
|
|
|
|
|
sprintf('modelfiles/general-config/%s/%s', date('Y'), date('m')),
|
|
|
|
|
|
$imageName,
|
|
|
|
|
|
'public'
|
|
|
|
|
|
);
|
2026-09-24 16:16:23 +02:00
|
|
|
|
|
2026-09-24 16:41:59 +02:00
|
|
|
|
$config->put('image', $path);
|
|
|
|
|
|
}
|
2026-09-24 16:16:23 +02:00
|
|
|
|
|
2026-09-24 16:41:59 +02:00
|
|
|
|
$config
|
|
|
|
|
|
->put('image_alt', $request->input('image_alt'))
|
|
|
|
|
|
->put('image_title', $request->input('image_title'))
|
|
|
|
|
|
->save();
|
2026-09-24 16:16:23 +02:00
|
|
|
|
|
2026-09-24 16:41:59 +02:00
|
|
|
|
if ($request->hasFile('image') && $ancienne && $ancienne !== $config->get('image')) {
|
2026-09-24 16:16:23 +02:00
|
|
|
|
Storage::disk('public')->delete($ancienne);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return redirect()
|
|
|
|
|
|
->route('bo.general-config.edit')
|
2026-09-24 16:41:59 +02:00
|
|
|
|
->with('success', 'Configuration mise à jour.');
|
2026-09-24 16:16:23 +02:00
|
|
|
|
}
|
2026-09-24 16:41:59 +02:00
|
|
|
|
}
|