['book', 'portion', 'chapter'], 'Course' => ['module', 'lesson'], 'Fitness Program' => ['phase', 'workout', 'exercise'], ]; public function run(): void { $repository = app(SetLevelRepository::class); foreach (app(SetRepository::class)->all() as $set) { $kinds = self::KINDS_BY_SET[$set->getName()] ?? null; if ($kinds === null) { continue; } $existingKinds = array_map(function ($level): string { return $level->getKind(); }, $repository->findBySet($set)); foreach ($kinds as $kind) { if (in_array($kind, $existingKinds, true)) { continue; } $repository->create(new CreateSetLevelDto( set: $set, kind: $kind, )); $existingKinds[] = $kind; } } } }