Support the ongoing development of Laravel.io →
Database Eloquent
Last updated 2 years ago.
0

Accessor will do the job:

// User model
public function getMetadataAttribute()
{
    return $this->usermeta->lists('meta_value','meta_key');
}

// call:
$user->usermeta;

This will load the relation if needed, and use existing collection if it's loaded already.

Last updated 2 years ago.
0

If I'm accessing this multiple times, won't that cause it to have to rebuild the array over and over?

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

SaintPeter saintpeter Joined 22 Feb 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.