There are two ways you can go with this. First is to loop through all the elements and renaming it. (maybe using the dot style accessors)
Second is you can have mutators in your model. Example :
To fetch photographer_users.username
as 'username' :
public function getPhotographerAttribute()
{
return $this->photographer()->username;
}
Thanks for your help, With the mutator, at which step should I call the getPhotographerAttribute, or will this be "automatically" always renamed? Sorry I haven't used yet the accessors and mutators so I am not very familiar with their use.
Regarding the first option of looping, I was keeping that as a backup if I couldn't find anything else... feels super long to do vs using the premaid collection
They are automatically called when you access that attribute.
Thanks, I ended up using the array solution that way I could add extra external datas I needed, worked out perfectly! :-)
Hi commandantp
Would you mind sharing your idea, i still try to have an alias array to rename the db column name.
if there are much more records,will it have performace issue ?
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community