You're browsing the documentation for an old version of Livewire. Consider upgrading your project to Livewire 3.x.

Redirecting

Be amazing at Livewire
with our in-depth screencasts.
Watch Now

Introduction

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.

            
1class ContactForm extends Component
2{
3 public $email;
4 
5 public function addContact()
6 {
7 Contact::create(['email' => $this->email]);
8 
9 return redirect()->to('/contact-form-success');
10 }
11}
            
1<div>
2 Email: <input wire:model="email">
3 
4 <button wire:click="addContact">Submit</button>
5</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('foo').
← Previous Topic Pagination
Next Topic → Flash Messages