Laravel sometimes validation rule

后端 未结 7 2182
孤街浪徒
孤街浪徒 2021-02-08 07:38

I am trying to validate a password field only if it is present. I want to allow someone to edit a user and they may or may not want to change the users password. So I thought I

7条回答
  •  抹茶落季
    2021-02-08 08:34

    "I am trying to validate a password field only if it is present."

    To do this, you can use the "nullable" rule within the validation system.

    For example:

    $this->validate($request, [
        'password' => 'sometimes|nullable|min:8',
    ]);
    

    For more information take a look at https://laravel.com/docs/5.6/validation section under "A Note On Optional Fields"

提交回复
热议问题