Use SoftDeletes with Livewire throws Property $casts not found

Livewire 2.4.1 with Laravel 8.34.0, if I add use Softdeletes; to a Component I immediately get this error:

Livewire\Exceptions\PropertyNotFoundException
Property [$casts] not found on component: [<component-name>]

Adding public $casts; does resolve the error.

Is this error expected and is this be the expected solution? Some of you might say, it works so all is good, but I want to be sure this is all good and proper, and perhaps will help someone else?

or perhaps it should be protected $casts;?

The SoftDeletes trait should go on your model and not inside your Livewire component.

1 Like

Removing ::withTrashed(); and adding

->when(!$this->active, function ($query) {
                    $query->onlyTrashed();
                })

allowed me to remove Softdeletes from the component. Thank you.