Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Oualidouka's avatar

Export excel file using Maatwebsite

Hello, I have a problem with export excel file using Maatwebsite , iam trying to get count of multiple values and group them by id.

this is my query :

    $data = DB::table('posts')
        ->select('employee_id',DB::raw('COUNT(statut = 1) AS condition_1'),DB::raw('COUNT(statut = 2) AS condition_2'))
        ->groupBy('employee_id')
        ->orderBy('employee_id');

    return $data;

this the controller :

public function export(Request $request)
{

     return Excel::download(new PostsExport(), 'Filename.xlsx');

}

the problem is when i export the file, it count just first condition and all other is a copy of it. can any one help, thank you.

0 likes
0 replies

Please or to participate in this conversation.