Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel5: Middleware or Validation?

I have a form which holds a url input and I need to validate that the given URL is not blacklisted by a 3rd party API, i'm not sure if I need to use a Middleware or create a specific form Request and verify that URL before passing on that request to a command. Any ideas?

like image 453
Broshi Avatar asked Apr 15 '15 13:04

Broshi


1 Answers

It's a job for Validator. Add your custom rule before validation:

Validator::extend('custom', function($attribute, $value, $parameters)
{
    // make 3rd party request using $value

    if (…) {
        return true;

    } else {
        return false;
    }
});

Don't forget to add error message string to resourses/lang/xx/validation.php file.

Read more: http://laravel.com/docs/5.0/validation#custom-validation-rules

like image 68
Limon Monte Avatar answered Nov 27 '22 07:11

Limon Monte