Fix contact mail bug (review feedback)

This commit is contained in:
S. Hattry 2022-11-28 12:08:55 +01:00
parent 9e7fad8ebb
commit e8d1669bae

View file

@ -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));