Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
CRAP
90.91% covered (success)
90.91%
10 / 11
AuthServiceProvider
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
5.02
90.91% covered (success)
90.91%
10 / 11
 boot
0.00% covered (danger)
0.00%
0 / 1
5.02
90.91% covered (success)
90.91%
10 / 11
<?php
namespace App\Providers;
use App\Authority;
use App\User;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Gate;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Schema;
class AuthServiceProvider extends ServiceProvider
{
    /**
     * The policy mappings for the application.
     *
     * @var array
     */
    protected $policies = [
        // 'App\Model' => 'App\Policies\ModelPolicy',
    ];
    /**
     * Register any authentication / authorization services.
     *
     * @return void
     */
    public function boot()
    {
        $this->registerPolicies();
        if(!Schema::hasTable('users')){return;}
        Gate::before(function ($user) {
            if ($user->isSuperAdmin()) {
                return true;
            }
        });
        if(!Schema::hasTable('authorities')){return;}
        $authorities = Authority::with('roles')->get();
        foreach($authorities as $authority) {
            Gate::define($authority->name, function($user) use ($authority) {
                return $user->hasRole($authority->roles);
            });
        }
    }
}