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

Sentry blog image

How I fixed 20 seconds of lag for every user in just 20 minutes.

Our AI agent was running 10-20 seconds slower than it should, impacting both our own developers and our early adopters. See how I used Sentry Profiling to fix it in record time.

Read more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay