Due to the default throttle middleware that will return its own response denying any access to the route you provide it after a certain number of requests, this is a throttle validation rule allowing the throttling of form requests so you're able to restrict only the submission of forms for the specific field of your choice.
For example, maybe a contact form with an email address can only be filled out once every 10 minutes per user.
Here is how you would perform this:
class ContactRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'email' => [
'required',
'email',
new Throttle('contact-form', $maxAttempts = 1, $minutes = 10),
],
'message' => [
'required',
'min:10',
'max:250',
],
];
}
Once the user has tried more than once in 10 minutes, a validation
error of "Too many attempts. Please try again later." will be
returned to the form under the email
key.
But @stevebauman if the user did not pass the message validation rules because eg. the text is too short he should get another attempt, right?
In this case, he would not be able to try again with the correct message because of the email throttle.
Is there a chance to implement this issue too, at the moment I have no idea?