vendredi 9 juillet 2021

Laravel call accessor each time model is retrieved

I have a model with one accessor defined. If I call the accessor it runs well but I'd like the accessor to execute each time the model is retrieved so I can replace attribute value with the accessor returned value.

This is my model:

protected $appends = ['name']; // Read on inernet that this would do the trick but don't

    public function getNameAttribute($value){
        return ($value." - ".$this->doors->num_doors." - ".$this->body->name);
    }

Now the accessor it's just executed when I access to the name attribue.

I'm working with Laravel 5.7



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/3AL2ed9
via IFTTT

Aucun commentaire:

Enregistrer un commentaire