我已经成功登录了adminpanel,但是使用中间件登录后重定向到仪表板时却无法正常工作。
登录控制器
if (Auth::attempt(['username' => $request->email, 'password' => $request->password]))
{
return redirect('/dashboard');
}
路线
Route::group(['middleware' => ['adminAuth']], function () {
Route::get('/dashboard', 'dashboardController@index');
});
仪表板控制器
public function index()
{
return 'admin dashboard';
}
adminAuthenticate.php中间件
public function handle($request, Closure $next)
{
if(Auth::check() && Auth::user()->role_code == '1'){
return $next($request);
}
return abort(404);
}
kernel.php
protected $routeMiddleware = [
'auth' => \App\Http\Middleware\Authenticate::class,
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,
'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class,
'can' => \Illuminate\Auth\Middleware\Authorize::class,
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
'password.confirm' => \Illuminate\Auth\Middleware\RequirePassword::class,
'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class,
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
'adminAuth' => \App\Http\Middleware\adminAuthenticate::class,
];
尽管我已成功登录,但始终返回“ 404”页面。
问题出在哪里?有人帮忙吗?预先感谢