重定向页面时 Laravel Auth 会话丢失

Kad*_*gun 5 php authentication session redirect laravel

我的 Laravel 会话存在身份验证问题。(之前是在同一个系统中运行的)

\n\n

这是我的用户控制器

\n\n
public function postLogin()\n{\n    $username = Input::get("username");\n    $password = Input::get("password");\n    $credentials = array\n    (\n        "username"=> $username,\n        "password" => $password,\n    );\n    if (Auth::attempt($credentials)) \n    {\n        echo Auth::user()->username;\n        exit();\n\n    }\n    else\n    {\n        return Redirect::to("user/login")->with("error_msg","Giri\xc5\x9f Ba\xc5\x9far\xc4\xb1s\xc4\xb1z! <br>L\xc3\xbctfen girdi\xc4\x9finiz bilgileri kontrol edip yeniden deneyin.");\n    }\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n

它返回用户名..但是当我重定向页面时会话丢失。

\n\n
public function postLogin()\n{\n    $username = Input::get("username");\n    $password = Input::get("password");\n    $credentials = array\n    (\n        "username"=> $username,\n        "password" => $password,\n    );\n    if (Auth::attempt($credentials)) \n    {\n        return Redirect::to(\'check_login\');\n\n    }\n    else\n    {\n        return Redirect::to("user/login")->with("error_msg","Giri\xc5\x9f Ba\xc5\x9far\xc4\xb1s\xc4\xb1z! <br>L\xc3\xbctfen girdi\xc4\x9finiz bilgileri kontrol edip yeniden deneyin.");\n    }\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n

还有我的路线:

\n\n
Route::get("check_login",function(){\n    echo Auth::user()->username;\n});\n
Run Code Online (Sandbox Code Playgroud)\n\n

结果:

\n\n
ErrorException\nTrying to get property of non-object\necho Auth::user()->username;\n
Run Code Online (Sandbox Code Playgroud)\n

Kha*_*hay 1

检查您的路线的postLogin()功能。如果您使用 in UserController,它应该在下面的post方法中。

Route::post('login', array('uses' => 'UserController@postLogin'));
Run Code Online (Sandbox Code Playgroud)

您提供的功能和路线与我完美配合,但如果您想检查用户是否保存在会话中,请尝试这样。

if (Auth::check())
{
    echo 'My user is logged in';
}
Run Code Online (Sandbox Code Playgroud)

如果您能提供您为此使用的所有路线,那就更好了。