首页 > 解决方案 > groupby 的 laravel 会话密钥

问题描述

嗨,我需要会话的 $clave,因为我可以删除它会话。我该怎么做?谢谢

$carrito=Session::get('cart');

$grouped = Session::get('cart')->groupBy('vendedor');

foreach($carrito as $clave => $carro) {
    echo $clave ; //I need to put these keys in the <a> to be able to delete the session of that item because when applying groupby it does not give me the session key. 
}

@foreach($grouped as $id => $value)
    @foreach($value as $key => $cartItem)
        <a href="#" onclick="removeFromCartView(event, {{ $clave}})" class="text-right pl-4"><i class="la la-trash"></i></a>
    @endforeach
@endforeach

标签: phplaravel

解决方案


我解决了->groupBy('vendedor', $preserveKeys = true)

@Carlos 在评论中回答


推荐阅读