conditional validation laravel based on role

49

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

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

    return $rules;
}

Comments

Submit
0 Comments