Laravel 4 - 急切的负载不打印

时间:2013-05-16 10:11:38

标签: laravel laravel-4

我尝试在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函数。

1 个答案:

答案 0 :(得分:0)

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