Crate Dummy Records In Laravel by Facker Factory

 By Default Laravel gives UserFactory

So we can create dummy records for user by folling tnker factory:-

php artisan tinker

factory(App\User::class, 200)->create();

App\User  User Model Path

200  Number of dummy records you can pass your choice


By this we got dummy data in few seconds.

Now Creating Factory for  Any Model by one command:-

php artisan make:factory ProductFactory

or (you can assin model name also)

php artisan make:factory ProductFactory --model=Product


These factories are placed in database/factories directory.


use Faker\Generator as Faker;


$factory->define(App\Product::class, function (Faker $faker) {

    return [

        'title' => $faker->title,

        'discription' => $faker->discription,

    ];

});

you can assin your field here.


php artisan tinker

factory(App\Product::class, 50)->create();


After this you got 50 products in few minutes.

Comments

Popular posts from this blog

Add Css And Js Files on Specific Page In laravel

Xpendy Pending

Laravel Join with two coloums