Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Comments

@phila088
Copy link

phila088 commented Apr 13, 2024

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.

@andrew1601
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants