Badge Color From Relationship

I have the following:
Tables\Columns\TextColumn::make('symptomLogs.symptom.name')
->badge()
->color(fn (string $state): string => Symptom::where('name',$state)->first()->color)
->sortable(),
Tables\Columns\TextColumn::make('symptomLogs.symptom.name')
->badge()
->color(fn (string $state): string => Symptom::where('name',$state)->first()->color)
->sortable(),
Context: I want the badge color to be the color set in the Symptom table. I am outputting a list of days which will show symptoms logged via the SymptomLogs table etc. Showing the name in the badge works just fine and I can use the Eloquent Query to get the color but I feel like there may be better way to accomplish this? .
0 Replies
No replies yetBe the first to reply to this messageJoin