TIP 01 / 09

Use Policies for Model-based Authorization.

When permissions depend on a specific model, keep the rules in a policy instead of repeating ownership checks across controllers. Laravel can discover a policy when it follows the usual model and policy naming convention.

Generate a policy with starter methods for a model:

bash
php artisan make:policy PostPolicy --model=Post

For example, restrict updates to the post owner:

code
public function update(User $user, Post $post): bool
{
    return $user->id === $post->user_id;
}

Then authorize the action at the controller boundary:

php
$this->authorize('update', $post);

Policies can also be used from routes, Blade, and the Gate facade, keeping the same rule available throughout the application.