表。現在,如果我限制我的結果說前3名(這是我在遊戲桌上的所有內容),那麼它會運行,但更多的是它會拋出異常......關係錯誤?Laravel口才關係只返回收效甚微
關係:
Game
public function Post()
{
return $this->belongsTo('App\Post', 'game_id');
}
Post
public function console()
{
return $this->hasOne('App\Console', 'id');
}
public function games()
{
return $this->hasOne('App\Game', 'id');
}
Console
public function Post()
{
return $this->belongsTo('App\Post', 'console_id');
}
更新
@joel @rashmi所以實際上傾銷$後,我在我的第四入口看到這...這是返回NULL
["relations":protected]=>
array(2) {
["games"]=>
NULL
前3個返回值。但是第四個都返回NULL。我又只有3 Games表
Games Table:
1 | game 1
2 | game 2
3 | game 3
而實際上在第三項是它具有爲2的值,但顯示比賽還有3名
posts table:
id | game id
1 | 2
2 | 3
3 | 2 (but showing "game 1" text)
是剛剛添加特定的名稱,以避免任何其他問題。 所以我做了開關,現在運行在我的postTransformer「試圖獲得非對象的屬性」:'遊戲'=> $ post-> games-> name, 正在返回的對象是遊戲,但... – Citti