Problem
There are many scenarios where being able to create a new Laravel user from the command line would be useful.
For example:
- You've deployed your project but forgotten to create an admin user
- You need to set up new user without creating a new seeder.
- You want to set up a test user without building an entire admin panel for managing users.
Having come across this recently, we found that using Laravel's Tinker feature gave us the most flexibility in solving this problem.
Solution
Whether you want to create your user locally, via SSH-ing into the server or through a command line interface like what Laravel Forge provides, here is how you can create a new Laravel user through the command line.
Enter 'Tinker' mode in your command line by running
Once in the Tinker interface, you can create an Eloquent query, just like you would in a controller.
To create a new user through this method, you will need to provide the required fields, as a key/value array, to populate your new user.
In this example, we're using Laravel's standard authentication set up therefore we want to pass through the name, email and hashed password.