vendredi 24 août 2018

How to populate a nested category table with Faker in Laravel?

I want to put the subcategory id into quote table but it seems too complicated! This is my try, obviously it ended up with a loop.

Here is the seeder:

public function run()
{
    factory(App\User::class, 50)->create()->each(function ($u) {

        $u->quotes()->save(
            factory(App\Quote::class)->make()
        );

    });
}

And the quote factory:

return [
    'text' => $faker->paragraph,
    'author_id' => factory('App\Author')->create()->id,
    'category_id' => factory('App\Category')->create()->id
];

The category factory:

return [
    'name' => $faker->text,
    'parent_id' => factory('App\Category')->create()->id
];



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2MxyKtJ
via IFTTT

Aucun commentaire:

Enregistrer un commentaire