Skip to content

[13.x] Resolve the UsePolicy attribute from parent classes - #61439

Merged
taylorotwell merged 2 commits into
laravel:13.xfrom
xurshudyan:use-policy-inheritance
Sep 6, 2026
Merged

taylorotwell merged 2 commits into
laravel:13.xfrom
xurshudyan:use-policy-inheritance

Conversation

@xurshudyan

Copy link
Copy Markdown
Contributor

#[UsePolicy] is only read from the class it's declared on, so a model that extends a base class carrying the attribute resolves no policy at all:

#[UsePolicy(DocumentPolicy::class)]
abstract class Document extends Model
{
}

class Invoice extends Document
{
}

Gate::getPolicyFor(Document::class);   // DocumentPolicy
Gate::getPolicyFor(Invoice::class);   // null
Gate::allows('view', $invoice);       // false — even for an admin

@taylorotwell
taylorotwell merged commit 3168427 into laravel:13.x Sep 6, 2026
56 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants