DEV Community

Biswarup Adhikari
Biswarup Adhikari

Posted on

A Quick Guide to Changing Laravel Passwords Using Tinker

To change a user's password in Laravel using Tinker, you can follow these steps:

Step 1: Open your terminal and navigate to your project directory.

Step 2: Type php artisan tinker to enter the Tinker shell.

Step 3: Retrieve the user by finding the user instance. For example, if you want to change the password for a user with ID 1, you can use the following command:

$user = App\Models\User::find(1);
Enter fullscreen mode Exit fullscreen mode

Step 4: Update the password for the user using the bcrypt function to encrypt the password. For example:

$user->password = bcrypt('new_password');
Enter fullscreen mode Exit fullscreen mode

Step 5: Save the changes by calling the save method on the user instance:

$user->save();
Enter fullscreen mode Exit fullscreen mode

Top comments (0)