Skip to content

Commit a92f6e1

Browse files
committed
权限初始化加载
1 parent 5383439 commit a92f6e1

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

app/Providers/AuthServiceProvider.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,20 @@ class AuthServiceProvider extends ServiceProvider
2121
*
2222
* @return void
2323
*/
24-
public function boot()
24+
public function boot(Gate $gate)
2525
{
26-
$this->registerPolicies();
27-
26+
$gate->before(function ($user, $ability) {
27+
if ($user->id === 1) {
28+
return true;
29+
}
30+
});
31+
$this->registerPolicies($gate);
32+
$permissions = \App\Models\Permission::with('roles')->get();
33+
foreach ($permissions as $permission) {
34+
$gate->define($permission->name, function ($user) use ($permission) {
35+
return $user->hasPermission($permission);
36+
});
37+
}
2838
//
2939
}
3040
}

0 commit comments

Comments
 (0)