Create new user php artisan tinker

To create a new user using PHP Artisan Tinker, you can follow these steps:

  1. Open your terminal and navigate to your Laravel project directory.

  2. Run the command php artisan tinker to start the Tinker shell.

  3. In the Tinker shell, you can use the following code to create a new user:

    $user = App\User::create([
     'name' => 'John Doe',
     'email' => '[email protected]',
     'password' => bcrypt('password'),
    ]);

    This code creates a new user with the name "John Doe", email "[email protected]", and password "password". The bcrypt function is used to hash the password.

  4. Press Enter to execute the code. You should see a confirmation message indicating that the user has been created successfully.

  5. You can verify that the user has been created by running the following code:

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

    This code retrieves the user with the email "[email protected]" and assigns it to the $user variable. You can then use the $user variable to access the user's properties and methods.

Note: Make sure to replace the email and password with your desired values. Also, make sure to use a secure password hashing algorithm like bcrypt to store passwords securely.