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(),


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? .
Was this page helpful?