I am trying to create and update users with laravel 5.4
This is the validation added for create user. It works.
$this->validate($request, [
'name' => 'required|max:255',
'email' => 'required|email|max:255|unique:users',
'password' => 'required|min:6|confirmed',
]);
On update the password field is not required. But validate the min:6 and confirmed rule if the password field is not null. Tried with sometimes
.. but not working..
$this->validate($request, [
'name' => 'required|max:255',
'email' => 'required|email|max:255|unique:users,email,'.$id,
'password' => 'sometimes|min:6|confirmed',
]);
The Validation Rule contains ISNULL(TEXT(Picklist_Field__c)). ISNULL determines if an expression is null (blank) and returns TRUE if it is. If it contains a value, this function returns FALSE.
Check if not null: whereNotNullSELECT * FROM users WHERE last_name IS NOT NULL; The equivalent to the IS NOT NULL condition in Laravel Eloquent is the whereNotNull method, which allows you to verify if a specific column's value is not NULL .
You should add all your validation logic in the passes() function. It should return true or false based on the logic you have written in the function. The message() function returns a string that specifies the error message to be displayed in case the validation fails.
try using nullable as a rule
'password' => 'nullable|min:6|confirmed',
see https://laravel.com/docs/5.8/validation#a-note-on-optional-fields
'password' => 'nullable|min:6|confirmed',
@Rejinderi's answer is correct!
'password' => 'sometimes|required|min:6|confirmed',
username = 'admin',
password = null // fail- required
username = 'admin',
password = 123 // fail- min:6
username = 'admin' // pass- validate only exist
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With