In my application, there are some guards (i.e. auth, student, teacher). I want to make users from each guard to be able to reset their password. So I made different reset password controllers for each guard. For example, StudentPasswordResetLinkController for student users and TeacherPasswordResetLinkController for teacher users. I also made different routes for each. In each controller, I add Password::broker('guard-name') in store function to specify which users should be referred. It looks something like this.
The student guard routes:
Route::get('/student/forgot-password', [StudentPasswordResetLinkController::class, 'create'])
->middleware('guest')
->name('student.password.request');
Route::post('/student/forgot-password', [StudentPasswordResetLinkController::class, 'store'])
->middleware('guest')
->name('student.password.email');
While in the controller:
public function store(Request $request)
{
$request->validate([
'email' => 'required|email',
]);
// Student guard
$status = Password::broker('student')->sendResetLink(
$request->only('email')
);
return $status == Password::RESET_LINK_SENT
? back()->with('status', __($status))
: back()->withInput($request->only('email'))
->withErrors(['email' => __($status)]);
}
With this, student users can receive the email in their email inbox, so I can assume that the application has selected the correct user guard (student instead of teacher or auth). But the problem is, the link sent to the email does not specify which guard should be referred to when it is clicked. The link is like:
http://myapp.local/reset-password?token=xxxxxx
This link took student users to auth instead of student guard so when they insert new password, the new password didn’t work. I expect the link look like this:
http://myapp.local/student/reset-password?token=xxxxxx
Can anyone figure out the solution for this?