73 lines
2 KiB
PHP
73 lines
2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Controllers\Fo\Pages;
|
|
|
|
use App\Contracts\Executor;
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Requests\Fo\ContactFormRequest;
|
|
use App\Mail\SendContactMail;
|
|
use App\Queries\Pages\GetPageQuery;
|
|
use App\Queries\Pages\GetPageQueryInput;
|
|
use App\Queries\Shops\GetShopQuery;
|
|
use App\Queries\Shops\GetShopQueryInput;
|
|
use Domain\Enums\StaticPageSlug;
|
|
use Domain\Models\ValueObjects\Slug;
|
|
use Illuminate\Contracts\View\View;
|
|
use Illuminate\Http\RedirectResponse;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Mail\Mailables\Address;
|
|
use Illuminate\Support\Facades\Config;
|
|
use Illuminate\Support\Facades\Mail;
|
|
|
|
class ContactController extends Controller
|
|
{
|
|
private const string SESSION_STATUS_KEY = 'status';
|
|
|
|
private readonly Address $mailToContact;
|
|
|
|
public function __construct(
|
|
private readonly Executor $executor,
|
|
) {
|
|
if (! Config::has('mail.to.contact')) {
|
|
throw new \UnexpectedValueException('Mail to contact address is not configured.');
|
|
}
|
|
$this->mailToContact = new Address(
|
|
Config::string('mail.to.contact')
|
|
);
|
|
}
|
|
|
|
public function showForm(Request $request, GetShopQuery $getShopQuery, GetPageQuery $getPageQuery): View
|
|
{
|
|
$status = $request->session()->get(self::SESSION_STATUS_KEY);
|
|
|
|
$magasin = $this->executor->execute(
|
|
$getShopQuery,
|
|
new GetShopQueryInput(),
|
|
);
|
|
|
|
$page = $this->executor->execute(
|
|
$getPageQuery,
|
|
new GetPageQueryInput(
|
|
new Slug(strval(StaticPageSlug::CONTACT->value()))
|
|
),
|
|
);
|
|
|
|
return view('fo.pages.contact', compact(
|
|
'status',
|
|
'magasin',
|
|
'page'
|
|
));
|
|
}
|
|
|
|
public function submitForm(ContactFormRequest $request): RedirectResponse
|
|
{
|
|
$contactData = $request->toValueObject();
|
|
|
|
Mail::to($this->mailToContact)
|
|
->send(new SendContactMail($contactData));
|
|
|
|
return back()->with(self::SESSION_STATUS_KEY, true);
|
|
}
|
|
}
|