Currently when I want to validate a select box I need to include all the values within the validation field.
public static $rules = array(
'type' => array('required', 'in:a,b,c,d')
);
Is there a best practise way to do this using an array?
For example: I have a long list of country names and want to include this as the validation list. The hacky way of doing this would be something along the lines of:
public static $rules = array(
'type' => array('required', 'in:'.implode(',', $countries))
);
Thanks
Laravel Form Request class comes with two default methods auth() and rules() . You can perform any authorization logic in auth() method whether the current user is allowed to request or not. And in rules() method you can write all your validation rule.
After checking if the request failed to pass validation, you may use the withErrors method to flash the error messages to the session. When using this method, the $errors variable will automatically be shared with your views after redirection, allowing you to easily display them back to the user.
A custom is possible, but a exist-rule can also do the job. More details on http://laravel.com/docs/validation#rule-exists
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With