0

我尝试在 Laravel 中链接三个表。到目前为止,我的代码是:

class Ownership extends Eloquent {
    protected $table = 'games_users';

    public function games() {
        return $this->belongsToMany('Game','games_users','owntype_id','games_id');
    }

    public function type() {
        return $this->hasMany('Owntype','id');
    }
}

我的控制器:

$own = Ownership::with('games','type')->get();

使用print_r,它似乎可以工作,但我无法打印它。我该怎么做?

编辑

带代码

$own = Ownership::with('games','type')->get();

foreach($own as $game) {
    echo $game->games;
}

我得到这个:

[{"id":1,"title":"Gra","pivot":{"owntype_id":1,"games_id":1}}][{"id":2,"title":"Gra 2","pivot":{"owntype_id":2,"games_id":2}}]

问题是:我不知道如何回显,并且我没有附加title任何功能。type

4

1 回答 1

0

我遇到了同样的问题并遇到了您未回答的问题,但是请尝试echo $game->games['title'],因为它是一个数组

于 2013-12-17T16:30:09.640 回答