How to confirm input selection in Laravel4

Currently, when I want to check the check box, I need to include all the values ​​in the check box.

public static $rules = array( 'type' => array('required', 'in:a,b,c,d') ); 

Is there a better way to do this with an array?

For example: I have a long list of country names, and I want to include this in the list of checks. A hacker way to do this would be something like:

 public static $rules = array( 'type' => array('required', 'in:'.implode(',', $countries)) ); 

thanks

+6
source share
2 answers

A custom way is possible, but an existing rule can also do the job. Learn more about http://laravel.com/docs/validation#rule-exists

+3
source

Create a selection menu with this array:

 $types = [ '' => 'select a type', 'one' => 'type one', 'a' => 'type a' ]; 

And the rules for validation:

 $rules = ['type' => 'required']; 

The first key of $ types is an empty string. It will be displayed as follows:

  <option value=''>select a type</option> 

When validating, the correct rule will not be validated.

Assuming all parameters in the selection menu are valid parameters.

+1
source

Source: https://habr.com/ru/post/947835/


All Articles