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

I'm not completely understanding what your question is, but you can use the collection keyBy method for things like this.

// Get all of the user's profile data. Set key of these by using the keyBy method.
$userProfiles = Profile::where('user_id', '=', 1)->get()->keyBy('field');

// Because we set the key by the field value, you can now access them in several ways
echo $userProfiles['facebook']->value; // echoes out 'myfbusername'
echo $userProfiles->get('facebook')->value; // echoes out 'myfbusername'
Last updated 9 years ago.
0

And what about adding multiple key/value on DB at once?

0

Sign in to participate in this thread!

Eventy

Your banner here too?

LonnyX lonnyx Joined 30 Mar 2015

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.