lundi 31 octobre 2016

How to use ->append v. protected $appends in Laravel

How do you append an attribute to one query but not all of the queries for a model. I know you can add attributes to all queries in the model by adding

protected $appends = ['icon'];

public function getIconAttribute(){
    return Gravatar::src($this->email, 100).'&r=g&d=mm';
}

I want to add it for only one query

$usernames = User::where('username', 'LIKE', '%'.$request->get('search').'%')
   ->append('icon')->get();

but that gives the error Call to undefined method Illuminate\Database\Query\Builder::append()

I can see the method but am feeling dumb http://ift.tt/2e6qRWf



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire