Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

yehuuu6's avatar

Do I need to create policies if I'm using model properties in Livewire 3

So according to docs if I am using model properties, the framework does all the authorization behind the scenes. And if I'm not, I need to create policies for my models. Is that right? I just wanted to make sure.

0 likes
6 replies
LaryAI's avatar
Level 58

Yes, you are correct. When using model properties in Livewire 3, the framework handles authorization behind the scenes. This means that if you bind a model directly to a Livewire component property, Livewire will automatically check the authorization policies for you.

However, if you are not using model properties and instead are manually handling data within your Livewire components, you will need to create and enforce policies yourself to ensure proper authorization.

Here is a brief example to illustrate both scenarios:

Using Model Properties (Automatic Authorization)

use Livewire\Component;
use App\Models\Post;

class EditPost extends Component
{
    public Post $post;

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

    public function save()
    {
        $this->post->save();
    }

    public function render()
    {
        return view('livewire.edit-post');
    }
}

In this example, Livewire will automatically check the authorization policies for the Post model when you bind it to the component property.

Not Using Model Properties (Manual Authorization)

In this example, you need to manually check the authorization using Gate::denies before performing any actions on the Post model.

In summary, if you use model properties in Livewire 3, the framework will handle authorization for you. If you do not use model properties, you will need to manually enforce authorization policies.

1 like
vincent15000's avatar
Level 63

Livewire model properties and policies are different.

Model properties allows you to handle the different properties of a model, whereas policies are to check if a user has a right on the model.

So yes, even if you are using Livewire model properties, you need to use policies to handle rights.

3 likes
Snapey's avatar

either way, you still have to actually write policies.

3 likes

Please or to participate in this conversation.