Kamran Ahmed Kamran Ahmed - 11 months ago 31
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

view to be sent as an email to the user with the reset
. In my
, 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>
- Larblog

Notice that, I am using
to access the token. Is it the right way that I am doing it? As it's always generating the same token.
again and again. And when I use this to reset the password, it says:
Invalid token received
. Also, I have checked in the
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?


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)) }}