ldc-nature-and-respect/app/Http/Requests/Fo/ContactRequest.php

43 lines
1.3 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;
}
/**
* 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',
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundBeforeLastUsed
'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());
}
}
];
}
}