65 lines
2 KiB
PHP
65 lines
2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Controllers\Front;
|
|
|
|
use App\Events\ContactRequested;
|
|
use App\Http\Requests\ContactRequest;
|
|
use Illuminate\Http\RedirectResponse;
|
|
use Inertia\Inertia;
|
|
use Inertia\Response;
|
|
use Uwil\LaravelCommon\Controllers\CommonController;
|
|
|
|
class ContactController extends CommonController
|
|
{
|
|
public function index(): Response
|
|
{
|
|
return Inertia::render('front/Pages/Contact', [
|
|
'profiles' => [
|
|
['label' => 'Consommateur', 'value' => 'consommateur'],
|
|
['label' => 'Éleveur', 'value' => 'eleveur'],
|
|
],
|
|
'countries' => [
|
|
['label' => 'France', 'value' => 'fr'],
|
|
['label' => 'Belgique', 'value' => 'be'],
|
|
],
|
|
'communities' => [
|
|
['label' => 'La Communauté Amont', 'value' => 'amont'],
|
|
['label' => 'La Communauté Aval', 'value' => 'aval'],
|
|
['label' => 'La Communauté Transformateurs', 'value' => 'transformateurs'],
|
|
['label' => 'La Communauté Scientifique', 'value' => 'scientifique'],
|
|
['label' => 'La Communauté Autres Parties Prenantes', 'value' => 'autres'],
|
|
],
|
|
]);
|
|
}
|
|
|
|
public function store(ContactRequest $request): RedirectResponse
|
|
{
|
|
$attachment = null;
|
|
|
|
if ($request->hasFile('attachment')) {
|
|
$file = $request->file('attachment');
|
|
$fileContents = file_get_contents($file->getRealPath());
|
|
|
|
if ($fileContents === false) {
|
|
abort(500, "Impossible de lire le fichier joint.");
|
|
}
|
|
|
|
$attachment = [
|
|
'name' => $file->getClientOriginalName(),
|
|
'mime' => $file->getMimeType(),
|
|
'content' => base64_encode($fileContents),
|
|
];
|
|
}
|
|
|
|
ContactRequested::dispatch(
|
|
$request->safe()->except('attachment'),
|
|
$attachment,
|
|
);
|
|
|
|
$request->hitEmailRateLimit();
|
|
|
|
return back()->with('success', true);
|
|
}
|
|
}
|