Answer the question
In order to leave comments, you need to log in
How to do orderBy on related table?
There are 2 tables:
- Products (HasMany Variants)
- Product Variants (linked via variant.product_id)
$products = Product::where('products.visible', 1)
->whereHas('variants', function ($query) {
$query->where('visible', 1);
})->orderBy('id', 'asc')
->paginate($products_per_page);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question