You can use normal where clausules:
public function games(){
return $this->belongsToMany(Game::class)->where('locked', 0);
}
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Every of my users can have more "games", I handle it over belongsToMany relation and the connection is saved in "middle table" 'game_users', model: GameUser.
Now I added field "locked"
User.php
public function games(){
return $this->belongsToMany(Game::class);
}
how can I add condition with model GameUser in this relation games()? Where GameUser locked = 0?
Please or to participate in this conversation.