我想從表order_status_history中的相關屬性的表訂單中獲取對象。從表order_status_history,我只需要狀態'審查'的最後一個記錄,所以我使用字段created_at排序asc。我的代碼到目前爲止,但我得到錯誤。Laravel whereHas eloqvent關係
$orders = Order::GetOrderHistoryReviewing()->get();
public function scopeGetOrderHistoryReviewing($query)
{
return $query->whereHas('statusHistory', function($q) {
$q->where('status', 'Reviewing')->orderBy('created_at','desc')->first();
});
}
我需要從第二臺關係的一個對象
這是我的錯誤
[2016-07-27 08:37:26] dev.ERROR: exception 'PDOException' with message 'SQLSTATE[42P01]: Undefined table: 7 ERROR: missing FROM-clause entry for table "orders"
LINE 1: ...ries" where "order_status_histories"."order_id" = "orders"."...
那麼,什麼是你的問題?您提到了一個錯誤,但我在您的帖子中看不到任何錯誤。如果你需要幫助,你需要提供更多的信息,從你得到的錯誤的文本,你已經嘗試迄今修復它等。 – Styphon
我認爲與第一isnt工作,我得到查詢錯誤 –
偉大的,你還沒有告訴我們這個錯誤。複製錯誤給你的確切單詞,並用它們更新你的問題... – Styphon