Kamran Ahmed Kamran Ahmed - 5 months ago 9
PHP Question

How to access the password reset token inside `emails.auth.reminder`?

I have just started learning Laravel and I was following the documentation. I got to know that Laravel uses

emails.auth.reminder
view to be sent as an email to the user with the reset
token
. In my
emails.auth.reminder
, I have put the following:

Hello Dear User,<br><br>
We have received a request from your account to reset your password at Larblog. Please use the following link to reset your password.<br><br>

{{ URL::to( 'user/resetpassword/' . Session::get('_token') ) }}<br><br>

If it wasn't you who tried to reset the password, simply ignore this email.<br><br>
Thanks,<br>
- Larblog


Notice that, I am using
Session::get('_token')
to access the token. Is it the right way that I am doing it? As it's always generating the same token.
Z7vKMT5ssfzeXsQcVkrYodoRmYnbjH0prdP83jBk
again and again. And when I use this to reset the password, it says:
Invalid token received
. Also, I have checked in the
password_reminders
table of my database and it's showing different token. When I use the token stored in the database, it works.

So, what's right way to access the token in the view that is sent via email?

Answer

I'm not certain what the method is to access a password reminder token directly, however normally when sending the email it's done via the Password::remind() function, rather than the usual email function. When using this the $token variable is automatically passed into the email view so that you can use it.

An example use of this function is:

Password::remind(Input::only('email'), function ($message)
{
    $message->subject('Password Reset');
});

And then accessing it in the view is as simple as:

To reset your password, complete this form: {{ URL::to('reset', array($token)) }}