Home » Php » php – laravel session key for groupby

php – laravel session key for groupby

Posted by: admin February 25, 2020 Leave a comment

Questions:

Hi I need the $clave of the session for i can delete it session.how i can do it? Thanks

$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
How to&Answers:

I resolved it with ->groupBy('vendedor', $preserveKeys = true)

Answered by @Carlos in the comments