Laravel 9 Generate Test or Dummy Data using Factory Tinker (ok)
https://www.itsolutionstuff.com/post/laravel-9-generate-test-or-dummy-data-using-factory-tinkerexample.html
Last updated
https://www.itsolutionstuff.com/post/laravel-9-generate-test-or-dummy-data-using-factory-tinkerexample.html
Last updated
Thay cách sử dụng Tinker cũ bị báo lỗi (ok)
https://www.itsolutionstuff.com/post/laravel-model-caching-performance-boost-tutorialexample.html
Giờ thay đổi thành https://stackoverflow.com/questions/63824410/unable-to-use-laravel-factory-in-tinker
If you need to see the example of laravel 9 factory tinker example. it's a simple example of laravel 9 factory seeder. it's a simple example of laravel 9 factories. This article will give you a simple example of a laravel 9 factory tutorial. Let's see below the example laravel 9 test record generate.
As we know testing is a very important part of any web development project. Sometimes we may require to add hundreds of records in your 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. So what you will do at that moment, You will add manually 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 to create dummy records to your model table. so in the laravel application, they provide a User model factory created by default. so you can see how to create records using the factory below:
Generate Dummy Users:
This by default created a factory of laravel. you can also see that on 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 I will give you a simple example of creating a product factory and you will understand how it works. so let's create a Product Model as like below:
app\Models\Product.php
now let's create our custom factory using bellow command:
Now they created new factory class for product and you can add as bellow code:
database\factories\ProductFactory.php
Using Faker you can be used to generate the following data types:
Numbers
Lorem text
Person i.e. titles, names, gender etc.
Addresses
Phone numbers
Companies
Text
DateTime
Internet i.e. domains, URLs, emails etc.
User Agents
Payments i.e. MasterCard
Colour
Files
Images
uuid
Barcodes
As you see above you can simply use data types. Now we are going to create 500 records of products table by following command:
Generate Dummy Product:
Read Also: Laravel 9 Socialite Login with Facebook Account Example
So i hope you created your 500 dummy records on products table.
Output:
I hope it can help you...