Support the ongoing development of Laravel.io →
posted 8 years ago
Session
Last updated 7 months ago.
0
Solution

This works, I guess...

$key = 'UserChoices';

Session::put($key, [10,22,31]);	/* Lets start with some data */

$choices   = Session::get($key); /* Get all ids. returns (array) */

$idExists  = in_array($choices, $id); /* Id exists ?  returns (bool) */

$choices[] = $idToAdd;	/* Add a single id */

$choices = array_merge($choices, $arrayOfIds);	/* Ad an array of ids */

unset( $choices[$idToRemove] );	/* Remove an id */

Session::put($key, $choices); /* Just save it ! */
Last updated 7 months ago.
0

Sign in to participate in this thread!

LoadForge

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2022 Laravel.io - All rights reserved.