forked from livewire/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauthorization.blade.php
More file actions
executable file
·38 lines (30 loc) · 988 Bytes
/
authorization.blade.php
File metadata and controls
executable file
·38 lines (30 loc) · 988 Bytes
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}
To authorize actions in Livewire, you can use the `AuthorizesRequests` trait in any component, then call `$this->authorize()` like you normally would inside a controller. For example:
@component('components.code', ['lang' => 'php'])
@verbatim
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
class EditPost extends \Livewire\Component
{
use AuthorizesRequests;
public $post;
public function mount(Post $post)
{
$this->post = $post;
}
public function save()
{
$this->authorize('update', $this->post);
$this->post->update(['title' => $this->title]);
}
}
@endverbatim
@endcomponent
If you use a different guard to authenticate your users then also add an entry to middleware_group in the livewire config file:
@component('components.code', ['lang' => 'php'])
@verbatim
...
'middleware_group' => ['web', 'auth:otherguard'],
...
@endverbatim
@endcomponent