I'm working on a Laravel application where I have implemented the password reset feature. However, I'm consistently running into the following error:
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'email' cannot be null (Connection: main, SQL: insert into password_resets (email, token, created_at) values (?, $2y$10$sFSxC9pgIbmRisHh4RZK5.j0cZNLlmogdlbiokfnKDLoSv4ng.SHW, 2024-01-29 14:44:11))",
Here's my code snippet from the 'sendResetPasswordEmail' function:
public function sendResetPasswordEmail(Request $request)
{
$request->validate(['email' => 'required|email']);
$email = $request->input('email');
$status = Password::sendResetLink(['email' => $email]);
return $status === Password::RESET_LINK_SENT
? back()->with(['status' => __($status)])
: back()->withErrors(['email' => __($status)]);
}
This is the body of my post request:
{
"email": "[email protected]"
}
My Pathetic Attempt at Debugging:
The problem was that in my Users table in the database, the email field had a capital 'E' like 'Email.' However, Laravel by default searches for 'email' with a lowercase 'e,' and that's why.
If you don't want to modify the column's name on your database you can paste the following code on your User's model:
public function getEmailForPasswordReset(): string
{
return $this->Email;
}
This code will overwrite the getEmailForPasswordReset on your User's model and you can customize the field that's going to be researched. Hope it helps some lost soul like mine!