|
|
@@ -5,6 +5,7 @@ namespace App\Providers;
|
|
|
use App\Authority;
|
|
|
use App\User;
|
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
+use Illuminate\Support\Facades\Cache;
|
|
|
use Illuminate\Support\Facades\Gate;
|
|
|
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
|
|
|
use Illuminate\Support\Facades\Schema;
|
|
|
@@ -32,13 +33,20 @@ class AuthServiceProvider extends ServiceProvider
|
|
|
if(!Schema::hasTable('users')){return;}
|
|
|
Gate::before(function ($user) {
|
|
|
if ($user->isSuperAdmin()) {
|
|
|
- return true;
|
|
|
+ Cache::put('isSuperAdmin', true);
|
|
|
+ }else{
|
|
|
+ Cache::put('isSuperAdmin', false);
|
|
|
}
|
|
|
});
|
|
|
+
|
|
|
if(!Schema::hasTable('authorities')){return;}
|
|
|
$authorities = Authority::with('roles')->get();
|
|
|
foreach($authorities as $authority) {
|
|
|
Gate::define($authority->name, function($user) use ($authority) {
|
|
|
+ if(Cache::get('isSuperAdmin')
|
|
|
+ && $authority['permission']=='允许'){
|
|
|
+ return true;
|
|
|
+ }
|
|
|
return $user->hasRole($authority->roles);
|
|
|
});
|
|
|
}
|