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