
Automatic Policy Resolution is Coming to Laravel 5.8
Starting in Laravel 5.8, as long as policies and models are in the conventional locations, you will not need to register them in the AuthServiceProvider
class:
In Laravel 5.8, as long as your policies and models are in the conventional locations, you do not need to register policies in the AuthServiceProvider…
— Taylor Otwell (@taylorotwell) February 18, 2019
If you have your models or policies in nonconventional locations, you can customize the policy guessing logic used to “look up” policies via the Gate:
Gate::guessPolicyNamesUsing(function ($class) {
// Do stuff
return $policyClass;
});
Laravel 5.7 determines policies from a configuration array found in the AuthServiceProvider
with the model as the key mapping to the associated policy:
protected $policies = [
'App\Model' => 'App\Policies\ModelPolicy'
];
You can continue to use the $policies
array to define your policies manually in Laravel 5.8, however, if you create new policies using the typical class path conventions for models and policies you don’t have to worry about adding additional policies to the configuration.
If you’re interested in the code that made this feature possible, here are a few commits you might want to check out:
- first pass at guessing policy from class
- add tests for policy resolution
- allow registration of guesser callback
Newsletter

Join 31,000+ others and never miss out on new tips, tutorials, and more.
Laravel Jobs

- Full Stack PHP (Mid-Level/Senior) Programmer
-
Remote
PhoneBurner - Software Developer
-
Remote, (US & Canada Only)
Patient Prism - Web Application Developer
-
Chicago Loop
Leading Real Estate Companies of the World - Multiple Laravel Developers (Part-Time)
-
Remote, USA Only
The Great Escape Room - Software Developer
-
Remote (US & Canada)
Alley