我有2個表用於獲取laravel雄辯中的內部連接查詢記錄,但不能與聯合數據獲取一起使用。Laravel雄辯加入使用屬於
表:類別
- ID
- 名
- cat_status
表:圖像
- 號
- 標題
- 遞減
- img_status
圖像控制器
//get all active images
ImageModel::where('status',true)->get();
public function getCategory() {
return $this->belongsTo('\App\Api\CategoryModel','cat_id');
GET類別活躍,只有
public function getActiveCategory() {
return $this->getCategory()->where('cat_status','=', 1);
}
我只需要哪一類是主動獲取,只有圖像。
if cat 1,2,3 3(is inactive)
image table
title=a1,cat_id=1,
title=a2,cat_id=2,
title=a3,cat_id=3
現在我得到所有3張圖片,我只需要前2張,因爲cat_id 3是不活動的。 任何想法如何加入狀態條件。
在此先感謝。
你屬於方法應該我在模型不在控制器。 –
對不起。我錯誤地添加了..在這裏粘貼在控制器部分。屬於條件是模型。 – shashik493
您可以使用預先加載選項來檢索。它在文檔中很清楚 –