public function associateMatters(Classroom $classroom, array $matters) { $ids = []; foreach ($matters['matters'] as $matter) { $ids[] = $matter['id']; } $classroom->matters()->sync($ids); }