each(function ($professor) { $sections = Section::inRandomOrder()->take(3)->get(); $professor->sections()->saveMany($sections); }); } }