50 lines
1.3 KiB
PHP
50 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests\Bo;
|
|
|
|
use Domain\Models\ValueObjects\Email;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Support\Facades\Config;
|
|
|
|
class BrevoWebhookRequest extends FormRequest
|
|
{
|
|
/**
|
|
* Determine if the user is authorized to make this request.
|
|
*/
|
|
public function authorize(): bool
|
|
{
|
|
return true;
|
|
}
|
|
|
|
public function getFromAddress(): Email
|
|
{
|
|
return new Email($this->string('items.0.From.Address'));
|
|
}
|
|
|
|
public function getToAddress(): Email
|
|
{
|
|
return new Email((string) $this->input('items.0.To.0.Address'));
|
|
}
|
|
|
|
public function getRawHtmlBody(): string
|
|
{
|
|
return $this->string('items.0.RawHtmlBody');
|
|
}
|
|
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*
|
|
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
|
|
*/
|
|
public function rules(): array
|
|
{
|
|
$expectedFormAddress = Config::string('mail.brevo_webook.expected_from_address');
|
|
|
|
return [
|
|
'items' => ['required', 'array', 'min:1'],
|
|
'items.0.From.Address' => ['required', 'email:rfc,spoof'],
|
|
'items.0.To.*.Address' => ['required', 'email:rfc,spoof', "in:{$expectedFormAddress}"],
|
|
'items.0.RawHtmlBody' => ['required', 'string', 'min:10'],
|
|
];
|
|
}
|
|
}
|