简体   繁体   English

ManyToMany雄辩的Laravel查询问题在哪里

[英]ManyToMany Eloquent Laravel query issue with whereHas

I have a ManyToMany relationship between two models: Album and Media . 我在以下两个模型之间存在ManyToMany关系: AlbumMedia

Here you can see Album model: 在这里您可以看到Album模型:

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

And here Media model: 这里是Media模型:

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

Now I want to select all medias that belongs to albums with public=1 . 现在,我要选择属于public=1专辑的所有媒体。 The eloquent query is this: 雄辩的查询是这样的:

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

But I get this error in whereHas line: 但是我在whereHas行中收到此错误:

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

I am using Laravel Framework 5.4.36 . 我正在使用Laravel Framework 5.4.36

It is like a 5.4 issue. 就像是5.4期。 ( https://github.com/laravel/framework/issues/26936 ) You should try to upgrade from 5.4 to 5.5 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