phplaravelvalidation

How do i add more validation rules to a laravel validation array?


I have a laravel validation rules array that I have defined like this.

$rules = array(
    'name' => 'required|regex:/(^[A-Za-z0-9 ]+$)+/',
    'email' => 'required|email',
    'mobile' => 'regex:/^\+?\d+$/',
);

$validation = Validator::make($input, $rules);

now depending on another if condition I want to add another validation rule into this array.

address => 'required'

how do I do it? I have tried the using array_push() function with the $rules array, but it doesn't work.


Solution

  • $rules['address'] = 'required';