mercredi 29 mars 2017

Add custom atrribute to json response

I have model something like that with custom attribute

class MyModel extends Model
{
    public function getExtraAttribute(){
        return 'some string'; //etc.
    }
}

And for controller method i have this

return MyModel::where('user_id', Auth::user()->id)->get();

But i don't see 'extra' attribute on json response

P.s. extra isn't column from database.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire