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 $title;

    protected $post;

    public function mount(Post $post)
    {
        $this->post = $post;
    }

    public function save()
    {
        $this->authorize('update', $this->post);

        $post->update(['title' => $this->title]);
    }
}
← Previous Topic

Validation

Next Topic →

Pagination