public function associateStudents(Classroom $classroom, array $students) { $ids = []; foreach ($students['students'] as $student) { $ids[] = $student['id']; } $classroom->students()->sync($ids); }