56 lines
1.5 KiB
PHP
56 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests\Fo;
|
|
|
|
use App\Lib\Helpers\ToolboxHelper;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Validation\ValidationException;
|
|
|
|
class ContactRequest extends FormRequest
|
|
{
|
|
/**
|
|
* Determine if the user is authorized to make this request.
|
|
*
|
|
* @return boolean
|
|
*/
|
|
public function authorize(): bool
|
|
{
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Prepare the data for validation.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function prepareForValidation(): void
|
|
{
|
|
$this->merge([
|
|
'terms' => $this->terms ? true : false
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*
|
|
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array|string>
|
|
*/
|
|
public function rules(): array
|
|
{
|
|
return [
|
|
'first_name' => 'required|min:1',
|
|
'last_name' => 'required|min:1',
|
|
'email' => 'required|email:rfc,spoof,dns,strict',
|
|
'message' => 'required|string|min:10',
|
|
'terms' => 'accepted',
|
|
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed
|
|
'g-recaptcha-response' => function (string $attribute, mixed $value, \Closure $fail) {
|
|
try {
|
|
ToolboxHelper::validateRecaptcha($this, \config('services.google.recaptcha.version'));
|
|
} catch (ValidationException $e) {
|
|
$fail($e->getMessage());
|
|
}
|
|
}
|
|
];
|
|
}
|
|
}
|