How can I delete only a single item from an array in Laravel with Sessions. When I try to do it now with Session:pull
, it just deletes the whole session object with key estate.id
and with all the items in the array. I want to match only the object that has the same id as the id received from the input.
Simplified code
$estateId = Input::get('id', null);
if ($processType == "add") {
Session::push('estate.id', $estateId);
}
else {
if (in_array($estateId, $data)) {
$value = Session::pull('estate.id', $estateId);
}
}
Laravel会话服务没有提供从数组中删除值的内置方法,但是可以使用以下解决方法:
Session::put('key', array_diff(Session::get('key'), ['value']));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.