Reputation: 53
I have a ManyToMany relationship between two models: Album
and Media
.
Here you can see Album
model:
class Album extends Model
{
public function medias()
{
return $this->belongsToMany('\Api\Medias\Models\Media');
}
}
And here Media
model:
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
. 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:
local.ERROR: ErrorException: compact(): Undefined variable: operator in...
I am using Laravel Framework 5.4.36.
Upvotes: 1
Views: 168
Reputation: 891
It is like a 5.4 issue. (https://github.com/laravel/framework/issues/26936) You should try to upgrade from 5.4 to 5.5
Upvotes: 2