Recently, i viewed a couple of videos about ACL in laravel (https://laracasts.com/series/whats-new-in-laravel-5-1/episodes/16) and after i copied all of the code, i've ran into an error when i'm trying to do anything like migrating, opening tinker and etc. (basically everything that will trigger the frameworks code). It's because tables are not being created yet.
AuthServiceProvider.php
public function boot()
{
$this->registerPolicies();
foreach($this->getPermissions() as $permission) {
Gate::define($permission->name, function ($user) use ($permission) {
return $user->hasRole($permission->roles);
});
}
}
protected function getPermissions()
{
return Permission::with('roles')->get();
}
So you can't run php artisan migrate
because it'll throw an error (Missing 'permissions' table
).
Temp solution is to add this code into boot function, BEFORE foreach
loop
if (App::runningInConsole())
{
return;
}
But i just don't feel right to include this check for every request. Any ideas how can i fix this or defer this loop until the actual check is called?