lundi 14 mars 2016

Laravel call all attributes at once

How can I call all of my models attributes including the ones defined as accessors/mutators?

At the moment I am creating accessors/mutators like;

public function setSatisfiedWithQualityOfCourseAttribute($value)
{
    $this->attributes['group_answers']['satisfied_with_quality_of_course'] = $value;
}

public function getSatisfiedWithQualityOfCourseAttribute()
{
    if (isset($this->group_answers['satisfied_with_quality_of_course'])) {
        return $this->group_answers['satisfied_with_quality_of_course'];
    }

    return null;
}

And I can call them from my controller with something like $response->satisfied_with_quality_of_course but I need to be able to return all of them without explicitly calling them one at a time. Can I do that?

I need to call all "real" attributes and all "accessors".



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire