簡體   English   中英

ManyToMany雄辯的Laravel查詢問題在哪里

[英]ManyToMany Eloquent Laravel query issue with whereHas

我在以下兩個模型之間存在ManyToMany關系: AlbumMedia

在這里您可以看到Album模型:

class Album extends Model
{
    public function medias()
    {
        return $this->belongsToMany('\Api\Medias\Models\Media');
    }
}

這里是Media模型:

class Media extends Model
{
    public function albums()
    {
        return $this->belongsToMany('\Api\Medias\Models\Album');
    }
}

現在,我要選擇屬於public=1專輯的所有媒體。 雄辯的查詢是這樣的:

return $this->getModel()::whereHas('albums', function($query) {
                $query->where('public', '=', '1');
            })->get();

但是我在whereHas行中收到此錯誤:

local.ERROR: ErrorException: compact(): Undefined variable: operator in...

我正在使用Laravel Framework 5.4.36

就像是5.4期。 https://github.com/laravel/framework/issues/26936 )您應該嘗試從5.4升級到5.5

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM