Conditional validation in laravel

Sometimes we have to pass the conditional validation in laravel form validation in that case it provides a rule (sometimes) for conditional validation on input field which validate input data if it is present in input request.

Answers 1
  • Validate field if present in input request in laravel using sometimes rule

    use Illuminate\Support\Facades\Validator;
    $v = Validator::make($data, [
        'email' => 'sometimes|required|email',
    ]);
    
    0

    It will validate the input field if it’s present input request.

  • Back to code snippet queries related laravel