我有这个型号:
class Ownership extends Eloquent {
protected $table = 'game_user';
public function games() {
return $this->belongsToMany('Game');
}
public function type() {
return $this->belongsToMany('owntype');
}
}
Game
和 Owntype
的型号很简单 ...extends Eloquent
. 这是我拉取数据的方式:
$games = Ownership::with('games','type')->where('user_id','=','1')->get();
从理论上讲,它有效 . 实际上,不是,因为它返回空 games
和 owntype
集合 . 这是它返回的内容:http://paste.laravel.com/s94
如何获取 games
和 users
表格内容?我不想在foreach中使用 Game::find
,因为它会产生很多查询 .
1 回答
你需要在
with()
内传递一个数组 .即