你如何向一个查询添加属性,但不影响模型的所有查询。我知道你可以向模型的所有查询添加属性通过添加...
我希望您只为一个查询添加它。
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
append()
方法。 - Rwdappend
添加到集合中,但Taylor不同意。 - Rwd