69 lines
1.9 KiB
PHP
69 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Http\Requests\ContactFormRequest;
|
|
use App\Mail\SendContactMail;
|
|
use App\Models\Magasin;
|
|
use App\Models\Setting;
|
|
use App\Models\Content;
|
|
use Illuminate\Support\Facades\Mail;
|
|
use Illuminate\Http\Request;
|
|
|
|
class ContactController extends Controller
|
|
{
|
|
/**
|
|
* legal notice page
|
|
*
|
|
* @param Request $request
|
|
* @return \Illuminate\Contracts\View\View
|
|
*
|
|
* @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass
|
|
*/
|
|
public function contact(Request $request)
|
|
{
|
|
// @phpcs:enable
|
|
$status = $request->session()->get('status');
|
|
|
|
$magasin = Magasin::first();
|
|
$magasins = Magasin::all();
|
|
|
|
$content = Content::where('key', 'contact')->first();
|
|
|
|
return view('contact', compact('status', 'magasins', 'magasin', 'content'));
|
|
}
|
|
|
|
/**
|
|
* submit contact form
|
|
*
|
|
* @param ContactFormRequest $request
|
|
* @return \Illuminate\Http\Response
|
|
* @throws \RuntimeException If email missing.
|
|
*/
|
|
public function contactSubmit(ContactFormRequest $request)
|
|
{
|
|
/** @var \App\Model\Magasin|null */
|
|
$shop = Magasin::where('name', $request->shop)->first();
|
|
|
|
if ($shop and $shop->email_contact) {
|
|
/** @var string */
|
|
$toMail = $shop->email_contact;
|
|
} else {
|
|
/** @var string|null */
|
|
$toMail = \optional(Setting::where('key', 'send_contact_mail_to')->first())->value;
|
|
if (!$toMail) {
|
|
/** @var string|null */
|
|
$toMail = config('mail.from.address');
|
|
}
|
|
}
|
|
|
|
if (!$toMail) {
|
|
throw new \RuntimeException('Impossible de trouver un mail');
|
|
}
|
|
|
|
// Envoi du mail d'alerte.
|
|
Mail::to($toMail)->send(new SendContactMail($request));
|
|
|
|
return back()->with('status', true);
|
|
}
|
|
}
|