Support the ongoing development of Laravel.io →
Database Eloquent
Last updated 1 year ago.
0

You could use factories. https://laravel.com/docs/5.3/seeding If you pass an array in to the make and create methods they will get merged in to the data array the factory generated. If you use that along with faker you'll be fine

$category = factory(App\Category::class);

factory(App\User::class, 50)->create([
    'name' => 'jon',
    'category' => $category->id
    ])->each(function($u) {
    $u->posts()->save(factory(App\Post::class)->make(['title' => 'test']));
});
Last updated 7 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

nameless nameless Joined 26 Oct 2016

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.