Disable livewire error handling / modal

What seems to be the problem:

I have some components using the poll directive for refreshing data.
Whenever the model gets deleted, these components open a modal showing the 404 not found error.
I do not want that modal. I either want it to stay silent or a way of hooking into that error and for example generate a redirect to another page with a flash message.

Steps to Reproduce:

Create component with public eloquent based model property.
Use poll directive on component.
Delete model via db or something.
See error modal popping up.

Are you using the latest version of Livewire:

Yes

Do you have any screenshots or code examples:

Hey, @pr4xx

Is there any code you can provide?

Component:
class UserComponent extends Component { public User $user }
<div wire:poll>{{ $user->name }}</div>

Usage:
<livewire:user-component :user="$user"/>

Now delete the user while the page is in use and watch the modal popping up.
@skywalker

Where is deletion method?

There is no direct delete method on that component. The models gets deleted via a cleanup job scheduled in the kernel.

Can you provide the full code?

At least this part

I am not sure if I am not explaining my issue in an understandable way.
The cleanup job runs via horizon and does pretty much User::where(...)->delete().
Causing the model bound to the livewire component to be non existing. As soon as livewire polls again it tries to find that deleted model but cannot because I just deleted it.
What I want is to customize or better hide the error popup livewire is giving me when this event happens.

Alright,
You can Try to refresh the data after the deletion by

$this->users = $this->users->refresh();

I have no $this->users.
My problem is: how do I customize livewire behaviour in case of an exception?

I give you just an example.

Try to refresh the model collection after the deletion happened.

You can do the following:

<div wire:poll="refreshUsers">
  $users
</div>

In your component

public function refreshUsers()
{
 $this->users = $this->users->refresh();
}

I hope you got the idea, because I don’t know your implementation exactly.

Take a look at Polling in the background section.

For anyone stumbling across this: seems like there is already a method for that, even though I could not find it in the documentation:

https://github.com/livewire/livewire/pull/1146

1 Like