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

Image of Timescale

Timescale – the developer's data platform for modern apps, built on PostgreSQL

Timescale Cloud is PostgreSQL optimized for speed, scale, and performance. Over 3 million IoT, AI, crypto, and dev tool apps are powered by Timescale. Try it free today! No credit card required.

Try free

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs