gpt4 book ai didi

php - Laravel 5.1 Cookie 问题

转载 作者:可可西里 更新时间:2023-11-01 13:53:37 26 4
gpt4 key购买 nike

我试图在加载 View 时设置 cookie:

 $cookie = Cookie::make('mycookie', $myval, 43200);
$view = view('myview')->with($data);
return Response::make($view)->withCookie($cookie);

并在以后的请求中读取 cookie:

if (Cookie::has('mycookie')) {
//do something
}

Cookie 永远不会设置...我哪里出错了?

最佳答案

这可以可靠地使用 Laravel 设置 cookie:

 use Illuminate\Http\Request;
use Illuminate\Contracts\Cookie\Factory;

class MyClass
{

public function handle(Request $request, Factory $cookie)
{
$cookie->queue($cookie->make('myCookie', $request->someVal, 129600));
return redirect('/myPage');
}

}

关于php - Laravel 5.1 Cookie 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31144362/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com