It seems like the issue you're facing is that Filament is not automatically resolving the cast of your listing_status attribute when displaying it in the table. This is because Filament doesn't inherently know how to display custom cast types, such as the one provided by the spatie/laravel-model-states package.
To resolve this, you need to tell Filament how to display the listing_status attribute by using a custom column or accessor that resolves the state to a human-readable format. Here's how you can do it:
First, ensure that your ListingStatus state class has a method to return a human-readable label. If it doesn't, you can add one like this:
abstract class ListingStatus extends State
{
// ... existing code
public function label(): string
{
return static::$label;
}
}
Next, in your Ticket model, you can create an accessor to get the label of the listing_status:
class Ticket extends Model
{
use HasStates;
protected $table = 'ticket';
protected $casts = [
'listing_status' => ListingStatus::class,
];
// ... existing code
public function getListingStatusLabelAttribute(): string
{
return $this->listing_status->label();
}
}
Now, in your TicketResource, you can use this accessor to display the label instead of the integer value:
public static function table(Table $table): Table
{
return $table
->columns([
TextColumn::make('listing_status_label')->label('Status'),
]);
}
This will tell Filament to use the listing_status_label accessor from your Ticket model, which resolves the state to its label, and display that in the table instead of the raw integer value.
Remember to replace 'listing_status_label' with the actual name of the accessor you've created in your Ticket model, and 'Status' with the label you want to display in the table header.
By following these steps, you should be able to see the human-readable labels for your listing_status in the Filament admin panel.
