Laravel Password & Password_Confirmation Validation

前端 未结 7 1534
甜味超标
甜味超标 2020-12-23 17:16

I\'ve been using this in order to edit the User Account Info:

$this->validate($request, [
    \'password\' => \'min:6\',
    \'password_confirmation\'          


        
相关标签:
7条回答
  • 2020-12-23 17:50

    try confirmed and without password_confirmation rule:

    $this->validate($request, [
            'name' => 'required|min:3|max:50',
            'email' => 'email',
            'vat_number' => 'max:13',
            'password' => 'confirmed|min:6',
        ]);
    
    0 讨论(0)
  • 2020-12-23 17:51

    I have used in this way.. Working fine!

     $inputs = request()->validate([
            'name' => 'required | min:6 | max: 20',
            'email' => 'required',
            'password' => 'required| min:4| max:7 |confirmed',
            'password_confirmation' => 'required| min:4'
      ]);
    
    0 讨论(0)
  • 2020-12-23 18:03

    Try doing it this way, it worked for me:

    $this->validate($request, [
    'name' => 'required|min:3|max:50',
    'email' => 'email',
    'vat_number' => 'max:13',
    'password' => 'min:6|required_with:password_confirmation|same:password_confirmation',
    'password_confirmation' => 'min:6'
    ]);`
    

    Seems like the rule always has the validation on the first input among the pair...

    0 讨论(0)
  • 2020-12-23 18:07

    Try this:

    'password' => 'required|min:6|confirmed',
    'password_confirmation' => 'required|min:6'
    
    0 讨论(0)
  • 2020-12-23 18:09

    You can use the confirmed validation rule.

    $this->validate($request, [
        'name' => 'required|min:3|max:50',
        'email' => 'email',
        'vat_number' => 'max:13',
        'password' => 'required|confirmed|min:6',
    ]);
    
    0 讨论(0)
  • 2020-12-23 18:11

    It should be enough to do:

    $this->validate($request, [
        'password' => 'sometimes,min:6,confirmed,required_with:password_confirmed',
    ]);
    

    Make password optional, but if present requires a password_confirmation that matches, also make password required only if password_confirmed is present

    0 讨论(0)
提交回复
热议问题