【发布时间】:2017-03-13 23:54:20
【问题描述】:
如何将属性附加到一个查询而不是模型的所有查询。 我知道您可以通过添加
来为模型中的所有查询添加属性protected $appends = ['icon'];
public function getIconAttribute(){
return Gravatar::src($this->email, 100).'&r=g&d=mm';
}
我只想为一个查询添加它
$usernames = User::where('username', 'LIKE', '%'.$request->get('search').'%')
->append('icon')->get();
但这给出了错误Call to undefined method Illuminate\Database\Query\Builder::append()
我可以看到方法,但感觉很愚蠢 https://laravel.com/api/5.3/Illuminate/Database/Eloquent/Model.html#method_append
【问题讨论】: