You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
On closeModel(), getting error Livewire\Features\SupportLegacyModels\EloquentModelSynth::setDataOnModel(): Argument #1 ($model) must be of type Illuminate\Database\Eloquent\Model, null given
#442
Open
phila088 opened this issue
Apr 13, 2024
· 1 comment
When calling $this->closeModal() I am getting the above error. This is called as it is in the documentation, and I cannot locate anything else in the issues regarding this. Not sure where to start.
I am calling function confirmDelete() from a wire:click() on a button in the modal to confirm the delete of a record. The record deletes properly, it runs $this->dispatch() fine, and closes the modal, but then throws the error once closed.
EDIT:
After further testing, it has to do with the events. Any events fired cause the error. If I run $this->dispatch() the error shows after close, but is present on mobile view. If it is fired with $this->closeModalWithEvents() it is displayed after closing the modal.
The text was updated successfully, but these errors were encountered:
I ran into the same issue this week and thought I'd post here in case others find themselves in this situation too.
It happens because, by default, the modal component is not destroyed when $this->closeModal() is called. Instead, the state is kept alive. Because the record is deleted, it then throws the error as the model doesn't exist any more but it's properties are still being referenced. You need to override the destroyOnClose() method in your component class. It is referenced in the README, under the Changing Modal Properties section.
You override the static method like this:
public static function destroyOnClose(): bool
{
return true;
}
You can also configure this globally by publishing the configuration and changing the default behaviour.
When calling
$this->closeModal()
I am getting the above error. This is called as it is in the documentation, and I cannot locate anything else in the issues regarding this. Not sure where to start.I am calling function
confirmDelete()
from awire:click()
on a button in the modal to confirm the delete of a record. The record deletes properly, it runs$this->dispatch()
fine, and closes the modal, but then throws the error once closed.EDIT:
After further testing, it has to do with the events. Any events fired cause the error. If I run
$this->dispatch()
the error shows after close, but is present on mobile view. If it is fired with$this->closeModalWithEvents()
it is displayed after closing the modal.The text was updated successfully, but these errors were encountered: