vendredi 28 juillet 2017

Get Calculated Field from Eloquent only when it was declared

I'm working with Eloquent and Laravel 5, added a field at $appends attribute on model and a mutator to get it value. My issue is, how get this field only when it is called?

    public static $model = 'Model';
    protected $table = 'table';
    protected $primaryKey = 'idtable';   
    public $incrementing = false;
    public $timestamps = false;

    protected $appends = ['DescComposta'];

    //Mutators
    public function getDescCompostaAttribute()
    {
        return $this->attributes['desc_composta'] = 'yes';
    }

Thank you all!



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire