diff --git a/app/Http/Controllers/ContactController.php b/app/Http/Controllers/ContactController.php index 7409112..5bdcb46 100644 --- a/app/Http/Controllers/ContactController.php +++ b/app/Http/Controllers/ContactController.php @@ -38,25 +38,29 @@ class ContactController extends Controller * * @param ContactFormRequest $request * @return \Illuminate\Http\Response + * @throws \RuntimeException If email missing. */ public function contactSubmit(ContactFormRequest $request) { - $data = $request->all(); - - /** @var Magasin|null */ + /** @var \App\Model\Magasin|null */ $shop = Magasin::where('name', $request->shop)->first(); - if ($shop && $shop->email_contact) { + if ($shop and $shop->email_contact) { + /** @var string */ $toMail = $shop->email_contact; } else { - $toMailSetting = Setting::where('key', 'send_contact_mail_to')->first(); - if (empty($toMailSetting->value)) { + /** @var string|null */ + $toMail = \optional(Setting::where('key', 'send_contact_mail_to')->first())->value; + if (!$toMail) { + /** @var string|null */ $toMail = config('mail.from.address'); - } else { - $toMail = $toMailSetting->value; } } + if (!$toMail) { + throw new \RuntimeException('Impossible de trouver un mail'); + } + // Envoi du mail d'alerte. Mail::to($toMail)->send(new SendContactMail($request));