2025-10-22 17:09:48 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Forms;
|
|
|
|
|
|
|
|
|
|
use App\Http\Controllers\Controller;
|
|
|
|
|
use App\Http\Requests\Forms\ContactRequest;
|
2025-10-24 14:38:11 +02:00
|
|
|
use App\Services\ContactService;
|
2025-10-22 17:09:48 +02:00
|
|
|
use Illuminate\Http\RedirectResponse;
|
|
|
|
|
use Inertia\Inertia;
|
|
|
|
|
|
|
|
|
|
class ContactFormController extends Controller
|
|
|
|
|
{
|
2025-10-24 14:38:11 +02:00
|
|
|
public function __construct(protected ContactService $contactService) {}
|
2025-10-22 17:09:48 +02:00
|
|
|
/**
|
|
|
|
|
* Show the contact form page.
|
|
|
|
|
*/
|
|
|
|
|
public function create()
|
|
|
|
|
{
|
|
|
|
|
return Inertia::render('forms/contact');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Handle an incoming contact form submission.
|
|
|
|
|
* @throws \Illuminate\Validation\ValidationException
|
|
|
|
|
*/
|
|
|
|
|
public function store(ContactRequest $request): RedirectResponse
|
|
|
|
|
{
|
|
|
|
|
$validated = $request->validated();
|
2025-10-24 14:38:11 +02:00
|
|
|
try {
|
2025-10-26 00:16:25 +02:00
|
|
|
$this->contactService->registerNewContactRequest($validated);
|
2025-10-24 14:38:11 +02:00
|
|
|
} catch (\Throwable $e) {
|
|
|
|
|
\Log::error('Erreur lors de la création d\'un contact', [
|
|
|
|
|
'error' => $e->getMessage(),
|
|
|
|
|
'trace' => $e->getTraceAsString(),
|
|
|
|
|
'data' => $validated,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
return to_route('contact')->with('error', __('contacts.responses.error'));
|
|
|
|
|
}
|
2025-10-22 17:09:48 +02:00
|
|
|
|
|
|
|
|
return to_route('contact')->with('success', __('contacts.responses.success'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|