В моей базе данных у меня есть следующие таблицы:
quotes
-id
-quote_title
...
quote_items
-id
-quote_id
-product_id
products
-id
-product_name
-product_category_d
Я хочу добиться того, чтобы отсортировать результат моего запроса с помощью product_category_id.
Ниже приведен запрос.
$query = Quote::query();
$query->whereHas('quote_item' , function ($query) {
$query->whereHas('product' , function ($query) {
$query->orderBy('product_category_id');
});
});
$temp= $query->find($id);
Результат не показывает ошибок, но не в порядке.
Модель:
class Quote extends Model
{
public function QuoteItem()
{
return $this->hasMany('app\QuoteItem');
}
}
Модель:
class QuoteItem extends Model
{
public function Quote()
{
return $this->belongsTo('app\Quote');
}
public function Product()
{
return $this->belongsTo('app\Product');
}
}
Модель продукта:
class Product extends Model
{
public function QuoteItem()
{
return $this->hasMany('app\QuoteItem');
}
}