Ben Borgers

How to manually generate Laravel password resets

August 1, 2020

Instead of sending password resets via email, you can also generate one whenever you'd like using Laravel Tinker on the command line (even in production) and send it manually.

First, run php artisan tinker to open up Laravel Tinker. Then, use this command to generate a password reset token for the User with ID 1.

app('auth.password.broker')->createToken(User::find(1))

This returns a token and adds it (hashed) to the password_resets table of your database.

To use it, use this path (if your app was set up using Laravel Breeze or Laravel Jetstream):

/reset-password/{token}?email={email}

(If you’re using the older Laravel scaffolding, the link will be /password/reset/{token}?email={user_email_address}.)

To get this working in production on Laravel Vapor, I ran this command:

php artisan tinker --execute "error_log(app('auth.password.broker')->createToken(App\User::find(1)))"

The command wasn't actually returning the token in production until I wrapped it with error_log.

More blog posts

Subscribe to my newsletter for a monthly round-up of new blog posts and projects I’m working on!

Twitter ↗ RSS feed ↗