paklie's avatar
Level 1

eloquent get the customer with multiple times order...

hi all..(to the point)

i have 2 tables:

  • customers
  • orders

model customer hasMany order.

how to get the top ten customer who has multiple time ordering?

thanks for your support..

0 likes
4 replies
Tray2's avatar

The simplest would be something like

Customers::withCount('orders')->orderBy('order_count', 'desc')->limit(10)->get();
6 likes
paklie's avatar
Level 1

@Tray2 awesome..thanks for direct answer. sorry for newbe question..im just two weeks with laravel. i dont know laravel has built in method for count XD...

tisuchi's avatar
tisuchi
Best Answer
Level 70

@paklie If you feel that @tray2 answer helps you, please mark that answer as the best reply to solve this question.

3 likes
tisuchi's avatar

@paklie It's unfair!

You must choose @tray2 response as a BEST ANSWER, not mine.

I didn't provide any solution for you.

4 likes

Please or to participate in this conversation.