Can't redirect after delete?

What seems to be the problem: 404 error after delete(), redirect() doesn’t happen.

Steps to Reproduce: My script looks like the script written below. It shows a single Foo based on the url example.com/{foo}.

Once hitting delete({{$id}}) in my Blade component, the item is deleted from the database. However, the website returns a 404 error and the redirect doesn’t happen. Looks like Livewire re-renders the component directly after deleting the item. How can I prevent this from happening?

<?php
namespace App\Http\Livewire\Admin;

use App\Models\Foo;
use Livewire\Component;
use Illuminate\Support\Facades\Request;

class Foo extends Component
{
    public $foo_id, $name;

    // example.com/{foo}
    public function mount()
    {
        $this->foo_id = Request::route('foo');
    }

    // showing a single foo
    public function render()
    {
        $foo = Foo::findOrFail($this->foo_id);

        return view('livewire.foo', ['foo' => $foo]);
    }

    // delete a single foo
    public function delete($id)
    {
        $foo = Foo::find($id)->delete();

        // redirect after delete because
        // foo doesn't exists anymore in example.com/{foo}
        return redirect()->route('bar');
    }
}

Are you using the latest version of Livewire: v2.0

Do you have any screenshots or code examples: No

A couple of things to try.

$this->skipRender() 

has been suggested, add this to your delete function.

Alternatively.

    public function delete($id)
    {
        $foo = Foo::find($id)->delete();

        $this->foo_id = null;

        return redirect()->route('bar');
    }

then in render method, pass an empty Foo model to the view

public function render()
{
    $foo = Foo::firstOrNew(['id' => $this->foo_id]);

    return view('livewire.foo', ['foo' => $foo]);
}

Thanks, that did the trick…

which method did the trick?