2 回答

TA貢獻1786條經(jīng)驗 獲得超13個贊
所以我發(fā)現(xiàn)了問題所在。在控制器內(nèi)部,有人添加了以下行:
public function __construct()
{
$this->middleware('auth');
$this->middleware('role:admin');
}
我猜這覆蓋了auth.basic中間件?,F(xiàn)在它再次按預(yù)期工作!
無論如何,謝謝。

TA貢獻1799條經(jīng)驗 獲得超6個贊
// Route group
Route::group(['as'=>'admin.','prefix'=>'admin','namespace'=>'Admin','middleware'=>['auth','admin']], function (){
Route::get('dashboard','DashboardController@index')->name('dashboard');
});
// admin middleware
if(Auth::check() && Auth::user()->role->id == 1)
{
return $next($request);
}else {
return redirect()->route('login');
}
// RedirectIfAuthenticated.php
if (Auth::guard($guard)->check() && Auth::user()->role->id==1) {
return redirect()->route('admin.dashboard');
}else {
return $next($request);
}
// karnel.php file
use App\Http\Middleware\Adminmiddleware;
protected $routeMiddleware = [
'admin' => Adminmiddleware::class,
];
// LoginController
public function __construct()
{
if(Auth::check() && Auth::user()->role->id == 1)
{
$this->redirectTo = route('admin.dashboard');
}
$this->middleware('guest')->except('logout');
}
- 2 回答
- 0 關(guān)注
- 193 瀏覽
添加回答
舉報