Using this snippet:
public function exception($exception, $stopPropagation): void
{
dd($exception);
if ($exception instanceof ModelNotFoundException) {
$this->forceClose();
$stopPropagation();
}
}
If i throw a ModelNotFoundException i got an empty black modal on browser (Like the default modal for 404 but with black background).
With this snippet, i got the dump of the Exception with this type instead of ModelNotFoundException:
public function exception(Exception $exception, $stopPropagation): void
{
dd($exception);
if ($exception instanceof ModelNotFoundException) {
$this->forceClose();
$stopPropagation();
}
}
Exception {#1807 ▼ // app\Livewire\Traits
#message: ""
#code: 0
#file: "
vendor\laravel\framework\
src\Illuminate\Container\Container.php"
#line: 944
trace: {▶}
}
And with this snippet, i got the dump of ModelNotFoundException:
public function exception(ModelNotFoundException $exception, $stopPropagation): void
{
dd($exception);
if ($exception instanceof ModelNotFoundException) {
$this->forceClose();
$stopPropagation();
}
}
Illuminate\Database\Eloquent\ModelNotFoundException {#1807 ▼ // app\Livewire\Traits
#message: ""
#code: 0
#file: "
vendor\laravel\framework\
src\Illuminate\Container\Container.php"
#line: 944
#model: null
#ids: null
trace: {▶}
}
But this makes no sense, because the ValidationException is catched too and handled like ModelNotFoundException. 🤯
And finally i found a "solution", is a mandatory to use the exactly signature from the docs. 😒
This snippet:
public function exception($e, $stopPropagation): void
{
if ($e instanceof ModelNotFoundException) {
$this->forceClose();
$stopPropagation();
}
}
If the $e is changed to another word, like $exception, the hook doesn't work as expected. 😪
Hope this can help other devs. 🤓