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

Authorization

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:

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]);
    }
}

If you use a different guard to authenticate your users then also add an entry to middleware_group in the livewire config file:

...
'middleware_group' => ['web', 'auth:otherguard'],
...
← Previous Topic

File Uploads

Next Topic →

Pagination