Laravel5: middleware or verification?

I have a form that contains url input, and I need to check that this URL is not blacklisted by a third-party API, I'm not sure if I need to use Middleware or create a specific form Request and check this URL before submitting this request teamwork. Any ideas?

+5
source share
2 answers

This is a job for the validator. Add your custom rule before checking:

 Validator::extend('custom', function($attribute, $value, $parameters) { // make 3rd party request using $value if (…) { return true; } else { return false; } }); 

Remember to add the error message line to the resourses/lang/xx/validation.php file.

More details: http://laravel.com/docs/5.0/validation#custom-validation-rules

+9
source

Form validation does not apply to middleware. Therefore, it is better to create a form request class.

You will probably need a special validation rule. See Lemon Answer.

0
source

All Articles