create()->each(function ($user) { $brands = Brand::inRandomOrder()->take(rand(1, 3))->pluck('id'); $user->brands()->attach($brands); }); } }