if you have a dedicated model for assigned_users (e.g. UserPost), use this approach:
$factory->define(App\UserPost::class, function (Faker $faker) {
return [
'user_id' => factory(App\User::class)->create()->id,
'post_id' => factory(App\Post::class)->create()->id,
];
});
if you don't, use a DB table insert:
DB::table('assigned_users')->insert(
[
'user_id' => factory(App\User::class)->create()->id,
'post_id' => factory(App\Post::class)->create()->id,
]
);
and finally, if you want to use existing users/posts, use a callback
DB::table('assigned_users')->insert(
[
'user_id' => function () {
return App\User::all()->random()->id;
},
'post_id' => function () {
return App\Post::all()->random()->id;
},
]
);
that should yield some multiple assigned users by chance, or better yet amend the callback as you wish to randomize only couple of them