Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

laravel validation required if

use IlluminateSupportFacadesValidator;
use IlluminateValidationRule;
 
Validator::make($request->all(), [
    'role_id' => Rule::requiredIf($request->user()->is_admin),
]);
 
Validator::make($request->all(), [
    'role_id' => Rule::requiredIf(fn () => $request->user()->is_admin),
]);
Source by laravel.com #
 
PREVIOUS NEXT
Tagged: #laravel #validation #required
ADD COMMENT
Topic
Name
3+4 =