Skip to content

Required if another field not empty #144

Open

Description

@Rashid2kaz

Hello!
I have 2 fields - 'password' and 'confirm_password'.
I need:

  1. If 'password' empty - 'confirm_password' not required.
  2. If 'password' not empty - 'confirm_password' is required.

How do I describe the rules?

Activity

  1. Tropicalista commented on Jan 11, 2022

    @Tropicalista

    Have you tried with:

    $validation` = $validator->make($_POST + $_FILES, [
        'password'              => 'required|min:6',
        'confirm_password'      => 'same:password',
    ]);
    
  2. Rashid2kaz commented on Jan 12, 2022

    @Rashid2kaz
    Author

    Have you tried with:

    $validation` = $validator->make($_POST + $_FILES, [
        'password'              => 'required|min:6',
        'confirm_password'      => 'same:password',
    ]);
    

    Password can be empty.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions