2026-06-14 21:32:07 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Fo\Pages;
|
|
|
|
|
|
2026-09-30 15:49:20 +02:00
|
|
|
use App\Contracts\Executor;
|
2026-11-14 16:06:12 +01:00
|
|
|
use App\Cqs\Actions\Contact\SubmitContactForm;
|
2026-11-10 14:28:00 +01:00
|
|
|
use App\Cqs\Queries\Pages\GetPageQuery;
|
|
|
|
|
use App\Cqs\Queries\Pages\GetPageQueryInput;
|
|
|
|
|
use App\Cqs\Queries\Shops\GetShopQuery;
|
|
|
|
|
use App\Cqs\Queries\Shops\GetShopQueryInput;
|
2026-11-10 18:15:32 +01:00
|
|
|
use App\Http\Controllers\Controller;
|
|
|
|
|
use App\Http\Requests\Fo\ContactFormRequest;
|
2026-11-14 22:41:40 +01:00
|
|
|
use App\Jobs\SendContactMailJob;
|
2026-06-14 21:32:07 +02:00
|
|
|
use Domain\Enums\StaticPageSlug;
|
2026-09-30 15:49:20 +02:00
|
|
|
use Domain\Models\ValueObjects\Slug;
|
2026-06-14 21:32:07 +02:00
|
|
|
use Illuminate\Contracts\View\View;
|
|
|
|
|
use Illuminate\Http\RedirectResponse;
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
use Illuminate\Mail\Mailables\Address;
|
|
|
|
|
use Illuminate\Support\Facades\Config;
|
|
|
|
|
|
|
|
|
|
class ContactController extends Controller
|
|
|
|
|
{
|
2026-09-30 15:49:20 +02:00
|
|
|
private const string SESSION_STATUS_KEY = 'status';
|
|
|
|
|
|
2026-06-14 21:32:07 +02:00
|
|
|
private readonly Address $mailToContact;
|
|
|
|
|
|
2026-09-30 15:49:20 +02:00
|
|
|
public function __construct(
|
|
|
|
|
private readonly Executor $executor,
|
|
|
|
|
) {
|
2026-06-14 21:32:07 +02:00
|
|
|
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')
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-30 15:49:20 +02:00
|
|
|
public function showForm(Request $request, GetShopQuery $getShopQuery, GetPageQuery $getPageQuery): View
|
2026-06-14 21:32:07 +02:00
|
|
|
{
|
2026-09-30 15:49:20 +02:00
|
|
|
$status = $request->session()->get(self::SESSION_STATUS_KEY);
|
2026-06-14 21:32:07 +02:00
|
|
|
|
2026-09-30 15:49:20 +02:00
|
|
|
$magasin = $this->executor->execute(
|
|
|
|
|
$getShopQuery,
|
|
|
|
|
new GetShopQueryInput(),
|
|
|
|
|
);
|
2026-06-14 21:32:07 +02:00
|
|
|
|
2026-09-30 15:49:20 +02:00
|
|
|
$page = $this->executor->execute(
|
|
|
|
|
$getPageQuery,
|
|
|
|
|
new GetPageQueryInput(
|
|
|
|
|
new Slug(strval(StaticPageSlug::CONTACT->value()))
|
|
|
|
|
),
|
|
|
|
|
);
|
2026-06-14 21:32:07 +02:00
|
|
|
|
|
|
|
|
return view('fo.pages.contact', compact(
|
|
|
|
|
'status',
|
|
|
|
|
'magasin',
|
|
|
|
|
'page'
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-14 16:06:12 +01:00
|
|
|
public function submitForm(ContactFormRequest $request, SubmitContactForm $action): RedirectResponse
|
2026-06-14 21:32:07 +02:00
|
|
|
{
|
2026-11-14 16:06:12 +01:00
|
|
|
$contactData = $this->executor->execute(
|
|
|
|
|
$action,
|
|
|
|
|
$request->toSubmitContactFormInput(),
|
|
|
|
|
);
|
2026-06-14 21:32:07 +02:00
|
|
|
|
2026-11-14 22:41:40 +01:00
|
|
|
SendContactMailJob::dispatch(
|
|
|
|
|
$contactData,
|
|
|
|
|
$this->mailToContact->address,
|
|
|
|
|
$this->mailToContact->name,
|
|
|
|
|
);
|
2026-06-14 21:32:07 +02:00
|
|
|
|
2026-09-30 15:49:20 +02:00
|
|
|
return back()->with(self::SESSION_STATUS_KEY, true);
|
2026-06-14 21:32:07 +02:00
|
|
|
}
|
|
|
|
|
}
|