I was sick and tired building model factories for every table I wanted to test in my laravel applications. So I woke up this morning and decided to try and make a helper command about this. In a Laravel 5.4 application I am currently working on, I created a new command by using the usual artisan make:command



Next step was to make this command accessible from the Artisan CLI command.

App\Console\Kernel.php

It’s time to write the handler that will actually do the job! The idea is to output a block of text so I can easily paste it in Laravel’s model factories file. It would also be great to have some common values applied like the usual Carbon objects for date fields, some common methods from $faker and finally some default values and some tips regarding the type of each field. Enough talking, let’s see some code.

So by just running a simple command like this

You get this output

When I find some time, most probably I’ll make a package for it. Until then, give it a try and let me know what you think!