如何解决Laravel 权限:绕过身份验证提供程序的超级管理员不起作用
我正在使用 spatie 的 laravel-permission 包,并在我的应用程序上创建了角色和权限,并在 AuthServiceProvider 中为他们的文档中指定的超级管理员角色编写了绕过。它像魅力一样工作,突然它无缘无故停止工作,返回 403 错误。我已经重新启动了服务器并清除了路由缓存。我找不到停止工作的原因...
这是我的 AuthServiceProvider 和路由
认证服务提供者:
public function boot()
{
$this->registerPolicies();
// allows super-admin everywhere in the app
Gate::before(function (User $user) {
return $user->hasRole('super-admin') ? true : null;
});
}
路线:
// admin only management
Route::group(['prefix' => 'admin','middleware' => ['role:writer']],function () {
//admin dashboard
Route::get('/dashboard',[AdminController::class,'index'])->name('admin.dashboard');
// blog management
Route::get('articles',[AdminArticles::class,'index'])->name('admin.articles.index');
Route::get('articles/create','create'])->name('admin.articles.create');
Route::get('articles/my-articles','myArticles'])->name('admin.articles.myArticles');
Route::get('articles/{article}/edit','edit'])->name('admin.articles.edit');
Route::get('articles/{article}/delete','destroy'])->name('admin.articles.destroy');
Route::put('articles/{article}','update'])->name('admin.articles.update');
Route::post('articles','store'])->name('admin.articles.store');
});
Route::group(['prefix' => 'admin','middleware' => ['role:super-admin']],function() {
//pages
Route::get('/homepage',[HomepageController::class,'create'])->name('admin.home.create');
Route::get('/homepage/{homepage}/edit','edit'])->name('admin.home.edit');
Route::put('/homepage/{homepage}','update'])->name('admin.home.update');
Route::post('/homepage','store'])->name('admin.home.store');
//users
Route::get('users',[UsersController::class,'index'])->name('users.index');
Route::get('users/json','usersJson'])->name('users.json');
Route::get('users/create','create'])->name('users.create');
Route::get('users/{user}/delete','destroy'])->name('users.destroy');
Route::get('users/{user}/edit','edit'])->name('users.edit');
Route::put('users/{user}','update'])->name('users.update');
Route::post('users','store'])->name('users.store');
});
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。