我正在使用Laravel 5.3,我的模型Post
中有一个附加属性:
/*
* toJson
*/
protected $appends = ['count'];
还有一个神奇的方法:
public function getCountAttribute()
{
return Offer::where('id', '=', $this->id)->count();
}
因此,当我使用Eloquent获取 Post
模型时,例如使用 Post::get()
并且将其以 JSON 形式返回时,这个对象中总是有这个属性 count
。
我该如何指定我想要或不想要另一个附加属性?
Post::get()
不是一个有效的方法,您是否意味着all
? - Styphon