Look at the aggregate functions.
Feb 10, 2023
7
Level 1
How can i get best sellers query in laravel
I have Books table
and Orders table
order table have book_id, payment_id
i want to get best seller in books
How can i do query with best performance ?
It should give me array of books sorted with best seller
Book Model
public function orders(){
return $this->hasMany(Order::class);
}
Order Model
public function books(){
return $this->belongsTo(Book::class,'book_id');
}
public function payment(){
return $this->belongsTo(Payment::class,'payment_id');
}
Please or to participate in this conversation.