get(); Video::factory(10)->make()->each(function (Video $video, int $videoKey) use ($productModels) { $video->product_id = (rand(0, 1)) ? $productModels->random()->id : null; $video->order = $videoKey++; $video->saveQuietly(); }); $videoModels = Video::query()->get(); Recipe::query()->get()->map(function (Recipe $recipe) use ($videoModels) { $recipe->video_id = (rand(0, 1)) ? $videoModels->random()->id : null; $recipe->saveQuietly(); }); } }