laravel validator error message code example
Example 1: email validation in laravel
'email' => 'required|email|unique:users,email',
Example 2: laravel validator make custom message
$rules = [
'name' => 'required',
'email' => 'required|email',
'message' => 'required|max:250',
];
$customMessages = [
'required' => 'The :attribute field is required.'
];
$this->validate($request, $rules, $customMessages);
Example 3: laravel unique validation
unique:table,column,except,idColumn
############## Example : ################
############### For Updating
'email' => 'unique:users,email_address,' . $userId,
############### For Creating
'email' => 'unique:users,email_address',
Example 4: laravel validation custom message example
$rules = [
'name' => 'required',
'email' => 'required|email',
'message' => 'required|max:250',
];
$customMessages = [
'required' => 'The :attribute field is required.'
];
$this->validate($request, $rules, $customMessages);
Example 5: email validation in laravel
$validator = Validator::make($request->all(), []);
$validator->sometimes('email', 'unique:users,email', function ($input) {
return $input->email !== Auth::user()->email;
});