How to generate fake data using factory tinker in laravel 11 Example
In this article, I will show you How to generate fake data using factory tinker in laravel 11 application. As we know, testing is a very important part of any web development project. Sometimes we may require to add hundreds of records to our users table, or maybe thousands of records. Also, think about if you require to check pagination, then you have to add some records for testing. You Can Learn How to Install and Use Trix Editor in Laravel 11 So what will you do at that moment? Will you manually add thousands of records? What do you do? If you add manually thousands of records, then it can take more time. However, Laravel has a tinker that provides the ability to create dummy records for your model table. So in the Laravel application, they provide a User model factory created by default. You can see how to create records using the factory below: Generate Dummy Users: php artisan tinker User::factory()->count(5)->create() This by default created a factory of Laravel. You can also see that at the following URL: database/factories/UserFactory.php. Create Custom Factory: But when you need to create dummy records for your products, items, or admin table, then you have to create a new factory using the tinker command. Here, Read More
In this article, I will show you How to generate fake data using factory tinker in laravel 11 application. As we know, testing is a very important part of any web development project. Sometimes we may require to add hundreds of records to our users table, or maybe thousands of records. Also, think about if you require to check pagination, then you have to add some records for testing. You Can Learn How to Install and Use Trix Editor in Laravel 11
So what will you do at that moment? Will you manually add thousands of records? What do you do? If you add manually thousands of records, then it can take more time.
However, Laravel has a tinker that provides the ability to create dummy records for your model table. So in the Laravel application, they provide a User model factory created by default. You can see how to create records using the factory below:
Generate Dummy Users:
php artisan tinker
User::factory()->count(5)->create()
This by default created a factory of Laravel. You can also see that at the following URL: database/factories/UserFactory.php
.
Create Custom Factory:
But when you need to create dummy records for your products, items, or admin table, then you have to create a new factory using the tinker command. Here,
Read More