Set Tags Color base on database value

Hello everyone . I am trying to populate tags on table using badge and the color will base on database value .

Right now my solution was
 TextColumn::make('tag.name')
                    ->label('Tags')
                    ->badge()
                    ->color(function($state){
                        return Color::hex(Tag::where('name', $state)->first()->color);
                    }),


Which I think can be improve , because I dont want to re querying Tag again ..

Thank you πŸ˜„
Screenshot_2024-01-31_at_3.34.25_PM.png
Was this page helpful?