Add a Unique rule for user email validation in update/store requests

This commit is contained in:
Bubka 2023-03-10 15:57:34 +01:00
parent ffdd82504a
commit a2e0c52189
2 changed files with 26 additions and 2 deletions

View File

@ -25,8 +25,20 @@ public function rules()
{
return [
'name' => 'required|string|max:255',
'email' => 'required|string|email|max:255',
'email' => 'unique:App\Models\User,email|required|string|email|max:255',
'password' => 'required|string|min:8|confirmed',
];
}
/**
* Prepare the data for validation.
*
* @return void
*/
protected function prepareForValidation()
{
$this->merge([
'email' => strtolower($this->email),
]);
}
}

View File

@ -26,8 +26,20 @@ public function rules()
{
return [
'name' => 'required|string|max:255',
'email' => 'required|string|email|max:255',
'email' => 'unique:App\Models\User,email|required|string|email|max:255',
'password' => 'required',
];
}
/**
* Prepare the data for validation.
*
* @return void
*/
protected function prepareForValidation()
{
$this->merge([
'email' => strtolower($this->email),
]);
}
}