Lumen请求会话应用('会话')为空。重定向无法正常工作

时间:2015-12-20 09:49:32

标签: php laravel session lumen

在流明控制器上采用以下存储方法

public function store(Request $request, JwtToken $jwtToken, Redirector $redirector)
{
    $sessionData = $request->session()->all();
    $this->validate($request, [
        'username' => 'required',
        'password' => 'required'
    ]);
}

在$ sessionData中,会话中的所有数据都存在,包括前一个url。通过默认验证器时,它会调用app('session')->previousUrl(),并返回null

$request->session()上做同样的事情时,它就存在了。我不知道如果我弄乱了什么,或者这是一个流明的错误。

我尝试过Redis和File驱动程序。

2 个答案:

答案 0 :(得分:0)

您在bootstrap/app.php

上忘记了这一点
/*
|--------------------------------------------------------------------------
| Register Middleware
|--------------------------------------------------------------------------
|
| Next, we will register the middleware with the application. These can
| be global middleware that run before and after each request into a
| route or middleware that'll be assigned to some specific routes.
|
*/

$app->middleware([
    Illuminate\Cookie\Middleware\EncryptCookies::class,
    Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
    Illuminate\Session\Middleware\StartSession::class,
    Illuminate\View\Middleware\ShareErrorsFromSession::class,
    Laravel\Lumen\Http\Middleware\VerifyCsrfToken::class,
]);

答案 1 :(得分:0)

通过执行以下操作似乎是Lumen中的错误

public function store(Request $request, JwtToken $jwtToken)
{
    $sessionData = $request->session()->all();
    $this->validate($request, [
        'username' => 'required',
        'password' => 'required'
    ]);

    //use global redirect helper function
}

删除了重定向器引用并使用了全局帮助程序函数