It seems like the issue you're encountering is related to how Livewire serializes and deserializes properties when updating the component. When you toggle the $confirmationModal property, Livewire refreshes the component, and during this process, it serializes your public properties to the frontend and then deserializes them back into PHP when the request comes back.
The all() method on a collection returns an array, but it seems like Livewire is not preserving the original models within that array when it's being serialized and deserialized. Instead, it's converting them to arrays.
To ensure that your $guidelines property remains a collection of models, you can use the load() method to eager load the relationship and then access it as a collection. Here's how you can modify your mount method:
public function mount(Resource $app)
{
// ...
$this->guidelines = $app->links()->where('type', '=', ResourceLink::DOWNLOADABLE)->get();
// ...
}
By using get() instead of all(), you're ensuring that $guidelines is a collection of ResourceLink models, which should be preserved when Livewire serializes and deserializes the data.
Additionally, make sure that your ResourceLink model has the necessary casts for its attributes if you're using any non-standard types that need to be cast when being serialized.
If you still encounter issues, you can also consider using Livewire's protected $casts property to explicitly cast the guidelines property to a collection of models. However, this feature is available from Livewire version 2.5.0 onwards, and since you mentioned you're using Livewire 2, you might need to update Livewire to a newer version that supports this feature.
Here's how you would define the cast in your Livewire component if you were able to update:
protected $casts = [
'guidelines' => 'collection',
];
This tells Livewire to always treat the guidelines property as a collection, which should help maintain the correct type during the serialization process.
Remember to check the Livewire documentation for the version you are using, as the features and syntax may differ between versions.