I’m encountering an issue with generating a password reset link in my Laravel application within the forget_password_submit method. Despite attempting to construct the link using Laravel’s URL::to() helper function, the link doesn’t seem to be generated correctly. here i used mailtrap for testing mail.
Here’s my forget_password_submit method:
public function forget_password_submit(Request $request)
{
$request->validate([
'email' => 'required|email'
]);
$admin_data = Admin::where('email', $request->email)->first();
if (!$admin_data) {
return redirect()->back()->with('error', 'Email address not found!');
}
$token = hash('sha256', time());
$admin_data->token = $token;
$admin_data->update();
$reset_link = URL::to('admin/reset-password/' . $token . '/' . $request->email);
$subject = 'Reset Password';
$message = 'Please click on the following link: <br>';
$message .= '<a href="' . $reset_link . '">Click here</a>';
Mail::to($request->email)->send(new Websitemail($subject, $message));
return redirect()->route('admin_login')->with('success', 'Please check your email and follow the steps there');
}
Despite constructing the link using URL::to(), the link is not being generated as expected. I’ve ensured that the APP_URL variable in the .env file is correctly set, and my routes are properly defined.