Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Lara_Love's avatar

How can we display the contents and products inside the four carts?

We have a uuid column in the factors table, which is the uuid value At Each shopping cart is fixed.

If we want to display each shopping cart based on the uuid table. For example, there are twenty ids in the table that are related to four shopping carts. How can we display the contents and products inside the 6 factors?

data https://postimg.cc/7GqbZ44j

show https://postimg.cc/phMzQ3HB

Controller

$bill = Faktor::selectRaw('user_id, sum(price * quantity) as total, count(*) as count')
            ->groupBy('uuid')
            ->get();
        return view('home',compact('bill',

View

@foreach($bill as $name)
   @if($loop->first)
      <div class="col-lg-2 col-md-6 col-sm-12">
           <a class="noline text-light" href="{{ route('person',$name->uuid) }}">
              <p class="text-light"><i class="bx bx-user"></i>{{ $name->user_id }}</p>
          </a>
            <p class="text-light"><i class="bx bx-user"></i>{{ $name->price}}</p>
    </div>
 @endif
@endforeach
```
0 likes
5 replies
tykus's avatar

Do you want to show all four shopping carts' contents together in the same view template??? Or do you want to simply show the Cart that belongs to the current Session?

1 like
tykus's avatar
tykus
Best Answer
Level 104

@LoverCode you can make a query to fetch each Cart's total, count and user_id like this - I have shown a commented line where the user relationship is eager-loaded (if needed):

$carts = Faktor::selectRaw('user_id, sum(price * quantity) as total, count(*) as count')
//  ->with('user')
    ->groupBy('uuid')
    ->get();
1 like
Lara_Love's avatar

@tykus

this is my controller

$bill = Faktor::selectRaw('user_id, sum(price * quantity) as total, count(*) as count') ->groupBy('uuid') ->get(); return view('front.manager',compact('bill',

and show it route

@foreach($bill as $item)

{{ $item->name }}

@endforeach

and Error

SQLSTATE[42000]: Syntax error or access violation: 1055 'lara.faktors.user_id' isn't in GROUP BY

Lara_Love's avatar

@tykus I hope you are always healthy and cheerful wherever you are, my unknown friend. Thank you for your great help

Please or to participate in this conversation.