-1

Actually, I am new on cookies (haven't work on it) what I am trying to do is Whenever clients visit my site and read an article get the id of that read article (without login). whenever clients came back on the same site form the same device which he/she has visited Then hide article which has been already read show only not read articles.

I have to try to create cookies like this

Cookie::queue(cookie('key', 'value', $minute = 10));
request()->cookie('key');

but whenever I update value it only get only the latest value. so Is it possible to do it by using cookies? or is there any alternative that which I can use for making this possible?

Gufran Hasan
  • 8,910
  • 7
  • 38
  • 51
Dipendra Deshar
  • 65
  • 2
  • 12

1 Answers1

2

Yes, it is possible.Instead of using the simple value you have to use an array of ids.

Example:-

Cookie::queue(Cookie::make('seen_posts', json_encode([1,2]), $minutes));

Updating cookies

$seen_posts = json_decode($request->cookie('seen_posts'),true);

$seen_posts[] = 3;

Cookie::queue(Cookie::make('seen_posts', json_encode($seen_posts), $minutes));
4vedi.aayush
  • 126
  • 6
  • Thanks for you response but its not working well while i try it errors like this Symfony \ Component \ Debug \ Exception \ FatalThrowableError (E_RECOVERABLE_ERROR) Argument 2 passed to Symfony\Component\HttpFoundation\Cookie::__construct() must be of the type string or null, array given, called in D:\_coding\Freelance\efiling\vendor\laravel\framework\src\Illuminate\Cookie\CookieJar.php on line 69 Do i have done any mistakes? – Dipendra Deshar Nov 21 '18 at 08:57
  • Edited the answer – 4vedi.aayush Nov 21 '18 at 09:25
  • While insert first time it works well but while updating its not updating cookies //while updating can we filter duplicate id? – Dipendra Deshar Nov 21 '18 at 10:30