jeudi 16 novembre 2017

get attribute accessor only for specific method in laravel

I want to modify some values of my query result for API call. here's my query

public function modules()
{
    Module::select('id','name','image')->get()->toJson();
}

so I want to modify image value, add full path to it. I added accessor

public function getImageAttribute($image)
{
    return asset($image);
}

and it works fine, but the problem is now it will be affecting this column every time i try to retrieve it. is there way to use this accessor(getImageAttribute) only for modules method?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2zJFGwh
via IFTTT

Aucun commentaire:

Enregistrer un commentaire