【发布时间】:2015-11-15 15:59:54
【问题描述】:
我在 Eloquent 模型上有以下内容:
public function setGameName(\Game $game)
{
$this->gameName = $game->find($this->gameId)->name;
}
当我在使用toArray() 之前在模型上使用dd() 时,我得到以下信息:
Promotion {#251 ▼
#table: "Promotion"
#primaryKey: "promotionId"
#guarded: array:1 [▶]
#game: null
+gameName: "3Peaks"
#connection: null
#perPage: 15
+incrementing: true
+timestamps: true
#attributes: array:14 [▶]
#original: array:14 [▶]
#relations: array:5 [▶]
#hidden: []
#visible: []
#appends: []
#fillable: []
#dates: []
#dateFormat: null
#casts: []
#touches: []
#observables: []
#with: []
#morphClass: null
+exists: true
+wasRecentlyCreated: false
}
如您所见,gameName 在attributes 和original 之外。如果此时我在模型上运行toArray(),则返回的数组没有我需要的gameName 属性。任何帮助表示赞赏。
【问题讨论】:
标签: php mysql laravel model eloquent