You're browsing the documentation for an old version of Livewire. Consider upgrading your project to Livewire 3.x.
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.
1use Livewire\Component; 2 3class ContactForm extends Component 4{ 5 public $email; 6 7 public function addContact() 8 { 9 Contact::create(['email' => $this->email]);10 11 return redirect()->to('/contact-form-success');12 }13 14 public function render()15 {16 return view('livewire.contact-form');17 }18}
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