filter(fn (mixed $value): bool => is_string($value) && trim($value) !== '') ->values(); $reportInputTypes = config('medical-report.reporting_unit_input_types', []); collect(config('medical-report.finance_profiles', [])) ->each(function (array $profile) use ($reportingUnits, $reportInputTypes): void { $profileModel = Profile::query()->where('name', $profile['name'])->firstOrFail(); collect($profile['units'] ?? []) ->filter(fn (mixed $value): bool => is_string($value) && trim($value) !== '') ->values() ->each(function (string $unitName) use ($profileModel, $reportingUnits, $reportInputTypes): void { HospitalUnit::query()->updateOrCreate( ['slug' => Str::slug(Str::ascii($unitName))], [ 'profile_id' => $profileModel->id, 'name' => $unitName, 'is_reporting_unit' => $reportingUnits->contains($unitName), 'report_input_type' => $reportInputTypes[$unitName] ?? null, 'is_active' => true, ], ); }); }); } }