Mail: [email protected] Phone: +1(424)231-4091

Reset User Password With Tinker

When the default password recovery is unavailable, it's possible to reset a user password using Tinker. However, tinker is an app that allows executing arbitrating PHP code on your server. This will require some knowledge on PHP and the CLI.

Executing Tinker

In order to execute thinker, you need to open the CLI at the root of your installation and type:

php artisan tinker

This will open a new app where you can execute PHP code. We'll then get started by retrieving the user we want to edit and assigning that to a variable named "$user" by using the following code.

$user = App\Models\User::where( 'email', '[email protected]' )->first();

You'll make sure to replace '[email protected]' with the user email you want to change the password.

You should have an output like this.

If you have this output, it means the user has been found. Otherwise, the email doesn't match any existing user. Now we'll update the password by doing this.

$user->password = Hash::make( 'YourPasswordHere' );
$user->save();

This will change the password of the user to "YourPasswordHere". make sure to replace the term YourPassWordHere with the desired password. The second line of the code will save the user.

Troubleshooting

If the last command doesn't work, it might be related to Tinker not aliasing the "Hash" facade (technical word). You'll then need to use this long form:

$user->password = Illuminate\Support\Facades\Hash::make( 'YourPasswordHere' );
$user->save();

If you still can't reset your password, you can let us know.