Line 7 to 18 shows how can we filter the resulted collection on the results.
Finally, this returns an array of demographics with age, gender, and location as indexes.
$mixDemographics =DB::table('demographics')
->leftJoin('countries', 'demographics.country_id', '=', 'countries.iso_3166_2')
->where('user_id',$userId)
->get();
$demographics = [];
$demographics['age'] = $mixDemographics->filter(function ($demo) {
return ($demo->metric == 'AGE');
});
$demographics['gender'] = $mixDemographics->filter(function ($demo) {
return ($demo->metric == 'GENDER');
});
$demographics['location'] = $mixDemographics->filter(function ($demo) {
return ($demo->metric == 'COUNTRY');
});
return $demographics;
0 comments:
Post a Comment