| 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

1 | <?php
2 |
3 | namespace App\Providers;
4 |
5 | use App\Authority;
6 | use App\User;
7 | use Illuminate\Support\Facades\Auth;
8 | use Illuminate\Support\Facades\Gate;
9 | use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
10 | use Illuminate\Support\Facades\Schema;
11 |
12 | class AuthServiceProvider extends ServiceProvider
13 | {
14 | /**
15 | * The policy mappings for the application.
16 | *
17 | * @var array
18 | */
19 | protected $policies = [
20 | // 'App\Model' => 'App\Policies\ModelPolicy',
21 | ];
22 |
23 | /**
24 | * Register any authentication / authorization services.
25 | *
26 | * @return void
27 | */
28 | public function boot()
29 | {
30 | $this->registerPolicies();
31 |
32 | if(!Schema::hasTable('users')){return;}
33 | Gate::before(function ($user) {
34 | if ($user->isSuperAdmin()) {
35 | return true;
36 | }
37 | });
38 | if(!Schema::hasTable('authorities')){return;}
39 | $authorities = Authority::with('roles')->get();
40 | foreach($authorities as $authority) {
41 | Gate::define($authority->name, function($user) use ($authority) {
42 | return $user->hasRole($authority->roles);
43 | });
44 | }
45 | }
46 | }