0
我碰巧擁有:銷售型號:id, product_id, qty, s_price
;產品型號有:id, category_id, name
; id, name
如何從Laravel的相關模型進行查詢?
目前l可成功地使這個查詢:
$sales = Sale::orderBy('created_at', 'DESC')
->whereBetween('created_at', [$startDate, $endDate])
->whereBetween('qty', [$lQty, $uQty])
->paginate(11);
我知道CATEGORY_ID,想過濾出的銷售屬於特定類別的產品,具有分類模型。喜歡的東西:
$sales = Sale::orderBy('created_at', 'DESC')
->whereBetween('created_at', [$startDate, $endDate])
->whereBetween('qty', [$lQty, $uQty])
->where('category_id', '=', 5)
->paginate(11);
所以...有什麼問題嗎?你是否遇到某種錯誤?你得到了什麼結果/你期望得到什麼結果? –
我得到這個錯誤Column not found:1054'where子句'中的未知列'category_id'(SQL:select count(*)as'sales'的聚合,其中'created_at'在2016-08-15和2016-08-16之間和'qty'介於0和100000之間,'category_id' = 5) –
我明確定義了產品和銷售之間的關係 –