-
Notifications
You must be signed in to change notification settings - Fork 224
/
redirecting.blade.php
executable file
·38 lines (30 loc) · 1.1 KB
/
redirecting.blade.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
* [Introduction](#introduction)
## Introduction {#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.
@component('components.code-component')
@slot('class')
@verbatim
class ContactForm extends Component
{
public $email;
public function addContact()
{
Contact::create(['email' => $this->email]);
return redirect()->to('/contact-form-success');
}
}
@endverbatim
@endslot
@slot('view')
@verbatim
<div>
Email: <input wire:model="email">
<button wire:click="addContact">Submit</button>
</div>
@endverbatim
@endslot
@endcomponent
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`).
@component('components.tip')
Because Livewire works with Laravel's redirection system, you can use any notation you are used to like <code>redirect('/foo')</code>, <code>redirect()->to('/foo')</code>, <code>redirect()->route('foo')</code>.
@endcomponent