I'm storing fields and values in a key value style table. I want to store revisions of user data over time. When I select from their data I only want the latest value of each key.
http://sqlfiddle.com/#!2/d7138

I'm currently eager loading but this selects all keys in this array when I just want the last value for each key.
public function healthProfile()
{
return $this->hasMany('PortalUserMember', 'portal_user_id')
->whereIn('key', [
'health.profile.sex',
'health.profile.birthday_day',
'health.profile.birthday_month',
'health.profile.birthday_year',
'health.profile.height_ft',
'health.profile.height_in',
'health.profile.weight_lbs',
'health.profile.contact_street_1',
// Could be anything at any point.
'health.profile.mail_pharmacy_name',
'health.profile.mail_pharmacy_fax',
'health.profile.mail_pharmacy_phone'
]);
}
Update
I'm doing this as a temporary work around: