mysql - Laravel Model Factory Complex Relationship -


i'm having tough time in sorting how seed database fake data if relationship complex have 3 tables users, categories , posts each post assigned user_id , category_id.

i'm using code:

factory(app\user::class, 10)->create()->each(function($u) {     $u->posts()->savemany(factory(app\post::class, 4)->make()); }); 

this generating 10 users , each user has 4 posts means generating 40 posts absolutely fine further more want generate 20 categories , each category belongs 2 posts. how that?


Comments

Popular posts from this blog

neo4j - finding mutual friends in a cypher statement starting with three or more persons -

php - How to remove letter in front of the word laravel -

minify - Minimizing css files -