DEV Community

Cover image for How to generate fake data using factory tinker in laravel 11 Example
Saddam Hossain
Saddam Hossain

Posted on

1

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()
Enter fullscreen mode Exit fullscreen mode

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

Top comments (0)

Image of Stellar post

How a Hackathon Win Led to My Startup Getting Funded

In this episode, you'll see:

  • The hackathon wins that sparked the journey.
  • The moment José and Joseph decided to go all-in.
  • Building a working prototype on Stellar.
  • Using the PassKeys feature of Soroban.
  • Getting funded via the Stellar Community Fund.

Watch the video 🎥

👋 Kindness is contagious

Dive into this informative piece, backed by our vibrant DEV Community

Whether you’re a novice or a pro, your perspective enriches our collective insight.

A simple “thank you” can lift someone’s spirits—share your gratitude in the comments!

On DEV, the power of shared knowledge paves a smoother path and tightens our community ties. Found value here? A quick thanks to the author makes a big impact.

Okay