Laravel Auth ::尝试正在运行,但auth :: user()变为NULL

时间:2016-06-20 05:28:31

标签: php laravel-5.2

我是 Laravel 的新手。

现在我想使用middleware

所以请帮助我。

我的代码是:

    $input = Input::except('_token');

    if(Auth::attempt($input)){         
        return redirect()->intended('dashboard');
    }else{
        return Redirect::to(route('login'))
                ->with('message','Sorry, Wrong Username and password .');
    }

Auth::attempt工作正常,并按预期重定向到仪表板。

但是当我尝试从控制器检查Auth::check函数时,它返回else语句。

public function dashboard(){      
    if(Auth::check()){
      return View::make('dashboard');
    }else{
      return "Not logged in";
    }
}

如何解决问题?

session.php文件

'driver' => env('SESSION_DRIVER', 'file'),
'lifetime' => 120,
'expire_on_close' => false,
'encrypt' => false,
'files' => storage_path('framework/sessions'),
'connection' => null,
'table' => 'sessions',
'lottery' => [2, 100],
'cookie' => 'laravel_session',
'path' => '/',
'domain' => null,
'secure' => false,
'http_only' => true,

2 个答案:

答案 0 :(得分:0)

如果您正在使用子域,请在下面更改此行(config / session)

'domain' => null,
to

'domain' => '.yourdomain.com',

此外,如果您使用文件存储会话

'driver' => env('SESSION_DRIVER', 'file'),

然后检查您是否具有存储/框架/会话目录的写入权限。您也可以尝试更改数据库会话。

答案 1 :(得分:0)

在您使用控制器功能的路线上使用 auth 中间件

javascript function
相关问题