2

I have this code

           $days = [];
       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();
            $days []= $performanceTable;
                    }
            return $days;

the output is

[[{"userid":1,"pleads":2,"mleads":1,"aleads":1}],[{"userid":1,"pleads":2,"mleads":1,"aleads":1}]]  

The question is how to parse this with jQuery to access the values
Or better how to output them like this with php directly so it's easier to parse them with jQuery in a single array

[{"userid":1,"pleads":2,"mleads":1,"aleads":1},{"userid":1,"pleads":0,"mleads":0,"aleads":0}]
1
  • add content type header to your response header('Content-Type: application/json'); Commented Mar 24, 2019 at 3:04

1 Answer 1

1

You don't need jQuery. You can use JSON.parse() to turn json into a javascript object.

You can output $days[0] to remove the outer array.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.