Playing with ChatGPT to generate dummy/fake data.
Tags: chatgpt, database, laravel, webdev
Published: 2023-03-06 04:35:58

If you're a software engineer, you know how important dummy data!!

When you need to test some piece of software locally which interacts with data, it's crucial to have a set of dummy data created.

One way to do that is generating the dummy data manually which is the old school way.

But nowadays we can use a free open source library to accomplish this task.

People who have exposed to PHP, well aware with FakerPHP library. And if you are using some framework like Laravel, it has a seperate Seeder class which allows to seed the database tables with dummy data.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1joxvnq3owe6grwekhyy.png)
Therefore, we can call FakerPHP helper methods to generate dummy or fake data for us. 

But with all these libraries we can't see the generated data until the process is completed since it's a direct interaction with the database behind the scene.

I think we can use ChatGPT to overcome from this issue. While some people bothering whether ChatGPT will take over all the software engineering jobs, we can find smarter ways to use it to improve the efficiency as software engineers.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qsuy46s5l2ikj4roxn2h.jpg)
Let's jump into ChatGPT and let's start with a dummy data table prior exploring the database seeders.

Simply I started with the following command.

My intention is to create a dummy product data table with the given parameters when creating a product.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zdhwm2n2hyookvpdpf5q.png)

What will be the ChatGPT's reply?

This is the reply.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z29fuvuhjnigaoiufcjm.png)

It not only created a table filled with dummy data, but also provided a brief explanation too. How awesome right?

Then my idea was to convert those dummy data into JSON format which permits me later to copy and paste during my data populating process.

So I asked the following question.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/blcixik63skvdrf7idy5.png)

It was smart enough to provide me the generated data in JSON format.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/54f7w9915gp81sq8972u.png)

This is the complete output.
`[
  {
    "name": "Widget A",
    "sku": "WIDG001",
    "quantity": 10,
    "price": 29.99
  },
  {
    "name": "Widget B",
    "sku": "WIDG002",
    "quantity": 5,
    "price": 14.99
  },
  {
    "name": "Widget C",
    "sku": "WIDG003",
    "quantity": 20,
    "price": 9.99
  },
  {
    "name": "Thingamajig X",
    "sku": "THING001",
    "quantity": 15,
    "price": 49.99
  },
  {
    "name": "Thingamajig Y",
    "sku": "THING002",
    "quantity": 7,
    "price": 99.99
  },
  {
    "name": "Thingamajig Z",
    "sku": "THING003",
    "quantity": 3,
    "price": 199.99
  }
]
`
End of the response it had provided a brief explanation again as below.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jkmhgiegqr6cq9bwwp3f.png)

Do you think I stopped from there? NO!!

I wanted to check whether it can provide a specific PHP framework oriented solution.

So I asked the following question.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y9znl50xwm325o2mnvif.png)

It started to guide me with a step by step approach which was really cool.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4qy5qetpqwqsytksgcev.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j0n8z6lwhbpx5obyokw5.png)

Complete code.

```php
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;

class ProductsTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        $products = [
            [
                'name' => 'Widget A',
                'sku' => 'WIDG001',
                'quantity' => 10,
                'price' => 29.99
            ],
            [
                'name' => 'Widget B',
                'sku' => 'WIDG002',
                'quantity' => 5,
                'price' => 14.99
            ],
            [
                'name' => 'Widget C',
                'sku' => 'WIDG003',
                'quantity' => 20,
                'price' => 9.99
            ],
            [
                'name' => 'Thingamajig X',
                'sku' => 'THING001',
                'quantity' => 15,
                'price' => 49.99
            ],
            [
                'name' => 'Thingamajig Y',
                'sku' => 'THING002',
                'quantity' => 7,
                'price' => 99.99
            ],
            [
                'name' => 'Thingamajig Z',
                'sku' => 'THING003',
                'quantity' => 3,
                'price' => 199.99
            ]
        ];

        DB::table('products')->insert($products);
    }
}

```

End of the code as usual it was giving a brief explanation as well.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v5uoijr8lgqn00w6yhxd.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f5hlffs2upqjarsjv0tt.png)

Happy coding!!