How to Create User from the Tinker Command in Laravel?

By Hardik Savani January 29, 2024 Category : Laravel

Hey,

Now, let's see an example of laravel create dummy users. I would like to share with you laravel factory faker user. you will learn laravel create user tinker. if you want to see an example of laravel tinker create user factory then you are in the right place. So, let's follow a few steps to create an example of how to create user from tinker factory laravel.

Laravel provides a tinker console command to create dummy records in your app. Laravel Tinker is an interactive REPL console in the Laravel framework, allowing developers to execute PHP code directly in the command line. It provides a quick and convenient way to test code snippets, interact with the application's environment, and perform database queries using Eloquent.

In this example, I will show you how to create test users using the tinker console command. i will show you how to create a single user and multiple users using the tinker command. you can see both example commands below:

Laravel Create Single User using Tinker Factory Command:

In this example, start by typing the tinker command. After that, use the factory and create a function to make a user. Put the name and email in an array to create a user with those details. Just run these commands to make a pretend user in your Laravel app:

php artisan tinker

User::factory()->create(['name' => 'User 2', 'email' => 'user-2@mail.com']);

Laravel Create Multiple Users using Tinker Factory Command:

In this example, start by typing the tinker command. After that, use the factory, count and create function to create dummy number of users records. Just run these commands to make a pretend user in your Laravel app:

php artisan tinker

User::factory()->count(10)->create()

I hope it can help you...

Tags :
Shares