Redirecting

You may want to redirect from inside a Livewire component to another page in your app. Livewire supports the standard redirect response syntax you are used to using in Laravel controller.

use Livewire\Component;

class ContactForm extends Component
{
    public $email;

    public function addContact()
    {
        Contact::create(['email' => $this->email]);

        return redirect()->to('/contact-form-success');
    }

    public function render()
    {
        return view('livewire.contact-form');
    }
}
<div>
    Email: <input wire:model="email">

    <button wire:click="addContact">Submit</button>
</div>

Now, after the user clicks "Submit" and their contact is added to the database, they will be redirected to the success page (/contact-form-success).

Because Livewire works with Laravel's redirection system, you can use any notation you are used to like redirect('/foo'), redirect()->to('/foo'), redirect()->route('food').
← Previous Topic

Pagination

Next Topic →

Flash Messages

Laravel Intellow Cierra 1043 Labs JR Merritt Trustfactory