Laravel 5.2身份验证 - Auth :: user()返回NULL

时间:2016-03-02 06:16:12

标签: php authentication laravel-5.2

在我的控制器中,Auth::attempt($userdata)成功运行,但在其他函数中打印Auth::user()时,它返回NULL。可能出了什么问题?

这是route.php

Route::group(['prefix'=>'admin'],function(){

/*Admin Login & Reset & Logout Routes*/

Route::get('login',['as'=>'suprlogn','uses'=>'admin\AdminController@index']);
Route::post('dologin',['as'=>'dologin','before'=>'csrf','uses'=>'admin\AdminController@dologin']);

Route::group(['middleware' => 'web'], function () {

    Route::get('dashboard',['as'=>'dashboard','uses'=>'admin\AdminController@dashboard']);
   });

});

我的AdminController.php是这样的:

public function dologin(){ 
     $userdata=array(
        'username'=>Request::get('username'),   
        'password'=>Request::get('password')  
        );

    if(Auth::attempt($userdata)){
        // var_dump(Auth::user()); 
        return Redirect::to(route('dashboard'));
   } 
}

public function dashboard(){

 if (Auth::check())
    return View::make('admin.dashboard');
 else

    var_dump(Auth::user());exit;
}

我还将HTTP / kernal.php中间件堆栈更改为

 protected $middleware = [
        \Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
        \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,
];

它仍无法正常工作

0 个答案:

没有答案