62 lines
1.6 KiB
PHP
62 lines
1.6 KiB
PHP
|
|
<?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
|
|||
|
|
{
|
|||
|
|
$request->validate(
|
|||
|
|
['image' => 'required|image|mimes:jpeg,png,jpg|max:2048|dimensions:width=742,height=464'],
|
|||
|
|
['image.dimensions' => "L'image doit faire exactement 742 × 464 px."]
|
|||
|
|
);
|
|||
|
|
|
|||
|
|
$config = GeneralConfig::current();
|
|||
|
|
$ancienne = $config->get('image');
|
|||
|
|
|
|||
|
|
$photo = $request->file('image');
|
|||
|
|
$imageName = 'image-' . now()->format('YmdHis') . '.' . $photo->extension();
|
|||
|
|
|
|||
|
|
$path = $photo->storeAs(
|
|||
|
|
sprintf('modelfiles/general-config/%s/%s', date('Y'), date('m')),
|
|||
|
|
$imageName,
|
|||
|
|
'public'
|
|||
|
|
);
|
|||
|
|
|
|||
|
|
$config->put('image', $path)->save();
|
|||
|
|
|
|||
|
|
if ($ancienne && $ancienne !== $path) {
|
|||
|
|
Storage::disk('public')->delete($ancienne);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
return redirect()
|
|||
|
|
->route('bo.general-config.edit')
|
|||
|
|
->with('success', 'Image mise à jour.');
|
|||
|
|
}
|
|||
|
|
}
|