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

Please leave your appreciation by commenting on this post!

Everybody is welcome

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

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay