Store array inside Cookie

1

Is it possible to store an array within a Cookie ?

I'm trying this way:

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

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

But I get the error:

  

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

This same array works fine if I try to store in a session .

I'm using Laravel 5.6

    
asked by anonymous 14.07.2018 / 18:44

2 answers

1

Is not it easier to use session ?

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

I believe it is best for the situation, since the Cookie has some limitations regarding the data that you can put in it, especially in relation to stored data size .

    
14.07.2018 / 19:45
0

One way to solve the problem would be to serialize the array.

link

With the value as string you could already put it in the cookie.

    
14.07.2018 / 19:10