我在 laravel 5.4 中有这个功能,但出现错误。
$cart[$product->id] = $quantity;
var_dump($cart);
return redirect('catalogs')->withCookie(cookie()->forever('cart', $cart));
Run Code Online (Sandbox Code Playgroud)
var_dump($cart) 包含这个:
array(1) { [1]=> string(1) "1" }
Run Code Online (Sandbox Code Playgroud)
错误警告:
Method Symfony\Component\HttpFoundation\Cookie::__toString() must not throw an exception, caught ErrorException: Array to string conversion
Run Code Online (Sandbox Code Playgroud)
如果我只传递字符串值(不是数组),它就成功了。如果有什么方法可以在 Laravel 中存储数组 cookie?
谢谢你。