This commit refactors the import statements in various controllers and jobs to improve code organization and readability. Unused imports were removed, and necessary imports were added to ensure proper functionality.
73 lines
2.1 KiB
PHP
73 lines
2.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Controllers\Fo\Pages;
|
|
|
|
use App\Contracts\Executor;
|
|
use App\Cqs\Queries\Pages\GetPageQuery;
|
|
use App\Cqs\Queries\Pages\GetPageQueryInput;
|
|
use App\Cqs\Queries\Shops\GetShopQuery;
|
|
use App\Cqs\Queries\Shops\GetShopQueryInput;
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Requests\Fo\ContactFormRequest;
|
|
use App\Mail\SendContactMail;
|
|
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);
|
|
}
|
|
}
|