67 lines
2 KiB
PHP
67 lines
2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Requests;
|
|
|
|
use App\Http\Requests\Concerns\HasEmailRateLimit;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Uwil\LaravelCommon\Helpers\ToolboxHelper;
|
|
use Illuminate\Validation\Validator;
|
|
|
|
class ContactRequest extends FormRequest
|
|
{
|
|
use HasEmailRateLimit;
|
|
|
|
/**
|
|
* Determine if the user is authorized to make this request.
|
|
*/
|
|
public function authorize(): bool
|
|
{
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function rules(): array
|
|
{
|
|
ToolboxHelper::validateRecaptcha($this);
|
|
return [
|
|
'lastName' => ['required', 'string', 'min:3', 'max:50'],
|
|
'firstName' => ['required', 'string', 'min:3', 'max:50'],
|
|
'email' => ['required', 'email', 'email:strict,rfc,spoof', 'max:255'],
|
|
'phone' => ['required', 'string', 'max:10', 'regex:/^[0-9+\-\s]+$/'],
|
|
'profile' => ['required', 'string'],
|
|
'company' => ['nullable', 'string', 'min:2', 'max:60'],
|
|
'postalCode' => ['nullable', 'string', 'max:10'],
|
|
'city' => ['nullable', 'string', 'min:2', 'max:60'],
|
|
'country' => ['nullable', 'string'],
|
|
'subject' => ['required', 'string', 'min:3', 'max:100'],
|
|
'message' => ['required', 'string', 'min:5', 'max:255'],
|
|
'attachment' => ['nullable', 'file', 'max:2048', 'mimes:jpg,jpeg,png'],
|
|
'acceptsUsage' => ['required', 'accepted'],
|
|
];
|
|
}
|
|
protected function rateLimitPrefix(): string
|
|
{
|
|
return 'contact';
|
|
}
|
|
|
|
protected function rateLimitMaxAttempts(): int
|
|
{
|
|
return 3;
|
|
}
|
|
|
|
protected function rateLimitMessageKey(): string
|
|
{
|
|
return 'validation.rate_limit.too_many_attempts';
|
|
}
|
|
|
|
public function withValidator(Validator $validator): void
|
|
{
|
|
$validator->after(fn (Validator $v) => $this->applyEmailRateLimit($v));
|
|
}
|
|
}
|