Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

conditional validation laravel based on role

public function rules()
{
    // Standard rules
    $rules = [
        'field1' => 'required',     
        'field2' => 'required',
    ];

    if (auth()->user()->role === 'admin') {
        $rules['field3'] = 'required';
    }

    return $rules;
}
Source by laracasts.com #
 
PREVIOUS NEXT
Tagged: #conditional #validation #laravel #based #role
ADD COMMENT
Topic
Name
5+5 =