Laravel 5.4-Cookie队列 [英] Laravel 5.4 - Cookie Queue

查看:105
本文介绍了Laravel 5.4-Cookie队列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Laravel 5.4,并且写了类似的内容:

I'm using Laravel 5.4 and I wrote something like:

     Cookie::queue(
        'refresh_token',
        $data->refresh_token,
        864000, // 10 days
        null,
        null,
        false,
        true // HttpOnly
    );

    return response('hello world');

返回的响应不包含return response('hello world')->withCookie(...)的refresh_token cookie.

The returned response doesn't contain the refresh_token cookie while return response('hello world')->withCookie(...) does.

Laravel 5.4文档不再像5.0文档那样声明cookie排队. 这是否意味着该功能已在5.4版中删除,或者我在代码中犯了一个错误?

The Laravel 5.4 documentation doesn't anymore state queueing cookie as 5.0 doc does. Does it mean that the functionality has been removed in version 5.4 or did I make a mistake in my code?

出于完整性考虑,我使用的是Dingo API程序包,响应是经过精心设计的.

For sake of completeness, I'm using Dingo API package and the response is crafted it.

谢谢您的帮助.

推荐答案

我发现:

未对api请求启用Cookie排队,这就是为什么它不起作用的原因.

Cookie queuing is not enabled for api requests, this is the reason why it didn't work.

我必须在相应文件的中间件部分中添加:

I had to add in the middleware section of the appropriate file:

protected $middleware = [
        \App\Http\Middleware\TrustProxies::class,
        \App\Http\Middleware\CheckForMaintenanceMode::class,
        \Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
        \App\Http\Middleware\TrimStrings::class,
        \Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,

        //added below line at end of the array
        \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
    ];

打开文件 App/Http/Kernel.php ,如上述代码段所示,在protected $middleware数组中添加行\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,,然后再次测试它现在应该可以工作了.

Open file App/Http/Kernel.php add the line \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class, in protected $middleware array as displayed in above code snippet and test again it should work now.

这篇关于Laravel 5.4-Cookie队列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆