In Laravel, you may need to create a user without using a registration form, especially if you are writing tests in your application.
If we go to the user seeder, we will find this line:
This line invokes the
User::factory and creates 10 users with fictitious information when we run the database seeders.
However, if we need to create one user and perhaps pass information that we do not want to be false (i.e., the email), we can execute the
User::factory line directly from the Tinker console and create the user, as shown below:
User::factory()->create(['email' => 'email@example.com'])
You can also provide the count of how many users you want to create with specific credentials. The syntax below works for Laravel 8 and onwards.
User::factory()->count(10)->create(['email' => 'firstname.lastname@example.org'])
View all Courses