[12.X] Introduces UsePolicy attribute#54409
[12.X] Introduces UsePolicy attribute#54409SimonBroekaert wants to merge 3 commits intolaravel:12.xfrom
Conversation
Co-authored-by: Jeffrey Angenent <1571879+devfrey@users.noreply.github.com>
|
@taylorotwell , May I know the reason why this PR has been put on Draft? It's not clear to me if I have to make any code changes or not. Thanks! |
|
At least I know that Taylor wont look at draft PRs. So if you consider this one is ready for review I think you can just put it out of draft :) |
|
Thanks for your pull request to Laravel! Unfortunately, I'm going to delay merging this code for now. To preserve our ability to adequately maintain the framework, we need to be very careful regarding the amount of code we include. If applicable, please consider releasing your code as a package so that the community can still take advantage of your contributions! |
|
Thanks for your pull request to Laravel! Unfortunately, I'm going to delay merging this code for now. To preserve our ability to adequately maintain the framework, we need to be very careful regarding the amount of code we include. If applicable, please consider releasing your code as a package so that the community can still take advantage of your contributions! |
Description
This pull request introduces a
UsePolicyattribute that provides an alternative way to define a policy for a model using PHP 8.0+ attributes. This is useful for when your policy does not follow the naming conventions to automatically look up the correct policy. Even when the policy follows the naming convention, it may help developers by making it more clear that a specific policy is used and by making it more easy to navigate.Usage
Reasoning
This is inspired by the recent addition of the
UseFactoryattribute. It makes it easier to know which policy is used for a model, by defining it in the model class itself.Priority
The code is executed after looking through the defined policies and right before the guessing logic.
Testing
The PR includes a test to verify the Policy is found.