我在laravel 5中定义了一个中间件。但是当我登录时,它会将我重定向到仪表板,但仪表板没有显示,并且发生了错误。我上传了它的照片。 http://imgur.com/a/1fCwt
AdminAuth.php
<?php
namespace App\Http\Middleware;
use Closure;
use Auth;
class AdminAuth
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if(Auth::check())
{
$user = Auth::user();
return redirect()->route('admin_display_dashboard');
} else {
return redirect()->route('admin_display_login');
}
}
}
Kernel.php
<?php
namespace App\Http;
use Illuminate\Foundation\Http\Kernel as HttpKernel;
class Kernel extends HttpKernel {
protected $middleware = [
\Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
];
protected $middlewareGroups = [
'web' => [
\App\Http\Middleware\EncryptCookies::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\Illuminate\Session\Middleware\StartSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\App\Http\Middleware\VerifyCsrfToken::class,
],
'api' => [
'throttle:60,1',
],
];
protected $routeMiddleware = [
'auth' => \App\Http\Middleware\Authenticate::class,
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
'can' => \Illuminate\Foundation\Http\Middleware\Authorize::class,
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
'adminAuth' => \App\Http\Middleware\AdminAuth::class,
];
}
Route.php
Route::group(['middleware' => ['adminAuth']], function () {
Route::get('admin/dashboard', array('as'=>'admin_display_dashboard', 'uses'=>'AdminViewController@displayDashboard'));
});
答案 0 :(得分:1)
你的admin_display_dashboard()和admin_display_login()中的内容,你确定没有重定向等等。
同时试试这个
if(!Auth::check())
{
return redirect()->route('admin_display_login');
}
$user = Auth::user();
return $next($request);