Skip to content

Commit 18fcd4c

Browse files
fix: correct state formatting and relationships in CaseInfolist and Specialist model
- Updated `roleForDisplay` relationship in `Specialist` model to define `role_id` explicitly. - Fixed state handling for role display and full name formatting in `CaseInfolist`. - Improved handling of empty, missing, and lazy-loaded relationships in specialist roles.
1 parent b5bb8c2 commit 18fcd4c

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

app/Filament/Organizations/Resources/Cases/Schemas/CaseInfolist.php

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ public static function configure(Schema $schema): Schema
281281
if ($state === null || (is_countable($state) && count($state) === 0)) {
282282
return new HtmlString('<span class="text-gray-500">—</span>');
283283
}
284-
$pills = collect($state)->map(fn ($service) => '<span class="inline-flex items-center rounded-full bg-gray-100 px-3 py-1 text-sm font-medium text-gray-800">'.e($service->getLabel()).'</span>')->implode('');
284+
$pills = collect($state)->map(fn ($service) => '<span class="inline-flex items-center rounded-full bg-gray-100 px-3 py-1 text-sm font-medium text-gray-800">'.e($service).'</span>')->implode('');
285285

286286
return new HtmlString('<div class="flex flex-wrap gap-2">'.$pills.'</div>');
287287
})
@@ -438,20 +438,30 @@ public static function configure(Schema $schema): Schema
438438
TextEntry::make('user.full_name')
439439
->label(__('beneficiary.section.specialists.labels.name'))
440440
->formatStateUsing(function (mixed $state, TextEntry $entry): string {
441-
$specialist = $entry->getContainer()?->getRecord();
441+
$specialist = $entry->getRecord();
442442

443443
return $specialist instanceof \App\Models\Specialist && $specialist->user !== null
444444
? $specialist->user->full_name
445445
: '';
446446
}),
447-
TextEntry::make('roleForDisplay.name')
447+
TextEntry::make('role_display')
448448
->label(__('beneficiary.section.specialists.labels.roles'))
449-
->formatStateUsing(function (mixed $state, TextEntry $entry): string {
450-
$specialist = $entry->getContainer()?->getRecord();
449+
->state(function (TextEntry $entry): string {
450+
$specialist = $entry->getRecord();
451451

452-
return $specialist instanceof \App\Models\Specialist && $specialist->roleForDisplay !== null
453-
? $specialist->roleForDisplay->name
454-
: '';
452+
if (! $specialist instanceof \App\Models\Specialist) {
453+
return '';
454+
}
455+
if ($specialist->relationLoaded('roleForDisplay') && $specialist->roleForDisplay !== null) {
456+
return $specialist->roleForDisplay->name;
457+
}
458+
if ($specialist->role_id !== null) {
459+
$specialist->loadMissing('roleForDisplay');
460+
461+
return $specialist->roleForDisplay?->name ?? '';
462+
}
463+
464+
return '';
455465
}),
456466
])
457467
->columns(2)

app/Models/Specialist.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function role(): BelongsTo
4242
*/
4343
public function roleForDisplay(): BelongsTo
4444
{
45-
return $this->belongsTo(Role::class);
45+
return $this->belongsTo(Role::class, 'role_id');
4646
}
4747

4848
public function specialistable(): MorphTo

0 commit comments

Comments
 (0)