laravel / ideas

Issues board used for Laravel internals discussions.
939 stars 28 forks source link

[Proposal] Make guessing policies lowest priority #2378

Open gbradley opened 4 years ago

gbradley commented 4 years ago

Currently, if a model doesn't explicitly have a policy mapped, Laravel will attempt two things in this order:

  1. Guessing the policy name, optionally with a custom callback;
  2. Checking if the model is a subclass of a model mapping a policy.

I frequently use model subclasses, and came across an instance where Laravel guessed the wrong policy name rather than selecting the policy based on the parent class.

Is there a good reason for this order? I would suggest that guessing should be the fallback option after explicit mapping & parent mapping fail. I suspect this would be a low impact change, as presumably few developers rely on guessing policies for their subclassed models?