I am trying to get data from db into a single array
This what i have edit he Code Thanks Matt C
foreach ($list1 as &$day){
$pleads = \DB::table('leads')
->selectRaw('count(*)')
->whereColumn('owned_by_id', 'users.id')
->where('lead_source_id', 7)
->whereRaw("DATE(created_at) = '$day'");
$mleads = \DB::table('leads')
->selectRaw('count(*)')
->whereColumn('owned_by_id', 'users.id')
->where('lead_source_id', 3)
->whereRaw("DATE(created_at) = '$day'");
$aleads = \DB::table('leads')
->selectRaw('count(*)')
->whereColumn('owned_by_id', 'users.id')
->where('lead_source_id', 4)
->whereRaw("DATE(created_at) = '$day'");
$personalleads = \DB::table('users')
->where('id', $id) // User ID
->select('users.id')
->selectSub($pleads, 'pleads')
->selectSub($mleads, 'mleads')
->selectSub($aleads, 'aleads')
->get();
return $personalleads;
}
when i do this i get only 1 output ex:
[{"userid":1,"pleads":2,"mleads":1,"aleads":1}]
but what i want as result is below
[{"userid":1,"pleads":2,"mleads":1,"aleads":1},{"userid":1,"pleads":0,"mleads":0,"aleads":0},{"userid":1,"pleads":0,"mleads":0,"aleads":0},{"userid":1,"pleads":1,"mleads":0,"aleads":0},{"userid":1,"pleads":1,"mleads":0,"aleads":0},{"userid":1,"pleads":1,"mleads":0,"aleads":0},{"userid":1,"pleads":0,"mleads":0,"aleads":0}]
print_r of what i get
( [items:protected] => Array ( [0] => stdClass Object ( [userid] => 1 [pleads] => 2 [mleads] => 1 [aleads] => 1 ) ) ) ( [items:protected] => Array ( [0] => stdClass Object ( [userid] => 1 [pleads] => 0 [mleads] => 0 [aleads] => 0 ) ) ) ( [items:protected] => Array ( [0] => stdClass Object ( [userid] => 1 [pleads] => 0 [mleads] => 0 [aleads] => 0 ) ) ) ( [items:protected] => Array ( [0] => stdClass Object ( [userid] => 1 [pleads] => 1 [mleads] => 0 [aleads] => 0 ) ) ) ( [items:protected] => Array ( [0] => stdClass Object ( [userid] => 1 [pleads] => 1 [mleads] => 0 [aleads] => 0 ) ) ) ( [items:protected] => Array ( [0] => stdClass Object ( [userid] => 1 [pleads] => 1 [mleads] => 0 [aleads] => 0 ) ) ) ( [items:protected] => Array ( [0] => stdClass Object ( [userid] => 1 [pleads] => 0 [mleads] => 0 [aleads] => 0 ) ) )
Thank you very much
$dayanywhere. You're just getting the exact same data over and over again and putting it in the same place