我試圖獲得與圖像的關係一個所有用戶很多。凡在圖像表列類型是等於1Laravel雄辯的查詢問題
最近我創建。
User::with('Images')->has('Images')->get();
但它返回的所有圖像不僅與類型1;
我也試過
$a = User::defaultImage()->get();
和用戶模型DEF範圍
public function scopeDefaultImage($query) {
$query->whereHas('Images', function ($query) {
$query->where('default', 1);
})->get();
return $query;
}
,但它不與圖像返回關係,只有用戶
怎麼樣定義你們的關係? –
OM我的用戶模型我有公共函數圖像(){ 回報 $這個 - >的hasMany( '應用程序\圖片'); } –