Store array within Cookie

Asked

Viewed 131 times

0

It is possible to store a array within a Cookie?

I’m trying this way:

$carrinho = array(array('frete' => '', 'mercados' => array()));

Cookie::queue('carrinho', $carrinho, 525600);

But the error returns to me:

Argument 2 passed to Symfony Component Httpfoundation Cookie::__Construct() must be of the type string or null, array Given, called in /var/www/html/seusuper/vendor/Laravel/framework/src/Illuminate/Cookie/Cookiejar.php

That same array works normal if I try to store in a Session.

I’m using the Laravel 5.6

2 answers

1


It is not easier to use the session?

session(array('frete' => '', 'mercados' => array()));

I believe it is even the most appropriate for the situation, since the Cookie has some limitations in relation to the data you can put in it, especially in relation to the size of the stored data.

  • 1

    I will continue using Session even. I was not connected in this relation of sizes stored in cookies.

-1

  • O problema é que o cookie vai ficar assim: a:1:{i:0;a:2:{s:5:"frete";s:0:"";s:8:"mercados";a:0:{}}}. Then it is impossible to go through the cookie and manipulate the values afterwards.

  • @Diegovieira pode unserialize em Javascript

Browser other questions tagged

You are not signed in. Login or sign up in order to post.