It seems like you're encountering an issue with the serialization of the OrderStatus state class when using Livewire, which is a dependency of Filament. Livewire has some limitations on what kind of data it can handle, and custom objects like the states from the spatie/laravel-model-states package can cause issues.
To resolve this, you can create a computed property in your Livewire component that returns a simple type (like a string or an array) that represents the state, instead of trying to pass the state object itself to the Livewire component.
Here's an example of how you might adjust your Livewire component to handle this:
class OrderComponent extends Component
{
public $orderId;
public $orderStatusName;
public function mount($orderId)
{
$this->orderId = $orderId;
$this->loadOrderStatusName();
}
public function loadOrderStatusName()
{
$order = Order::findOrFail($this->orderId);
$this->orderStatusName = $order->status->label(); // Assuming you have a label method or similar to get a string representation
}
// ...
}
In your Livewire view file, you would then use {{ $orderStatusName }} to display the status, instead of trying to display the state object directly.
If you need to display different information based on the state, you can create multiple computed properties or a single property that returns an array with all the necessary information.
Remember to update your Livewire component whenever the state changes, so the displayed information is always up-to-date.
If you're using Filament's admin panel and encountering this issue within Filament's resources, you might need to create a custom column type or use a callback to convert the state object to a string when defining your resource's table columns.
Here's an example of how you might define a custom column in a Filament resource:
use Filament\Tables\Columns\TextColumn;
TextColumn::make('status')
->label('Status')
->formatStateUsing(fn ($state) => $state->label()), // Assuming you have a label method on your state class
This way, you're providing a simple string to Filament's table, which should be compatible with Livewire's serialization requirements.