yigitozmen
yigitozmen

Reputation: 957

Can't get all data from table with laravel raw query and group_concat

Although I have 3 different teacher reports on the table and all the dates are same, i can only get last teacher's report

        $report = DB::table('users')
        ->join('classreports', 'classreports.teacherId', '=', 'users.id')
        ->where('classreports.classId', '=', Input::get('classId'))
        ->where('classreports.reportDate', '=', $reportDate)
        ->groupBy('classreports.reportDate')
        ->select('users.fullName', 'classreports.reportDate', DB::raw('group_concat(classreports.report) as report'))
        ->get();
    return json_encode($report);

How can i get all teacher's report?

Thanks.

Upvotes: 0

Views: 474

Answers (1)

Jay Dhameliya
Jay Dhameliya

Reputation: 1699

You can try this

        ->groupBy('classreports.teacherId','classreports.reportDate')

Can group by teacherID and reportDate

Upvotes: 1

Related Questions