| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- <?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);
- });
- }
- }
- }
|