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

vincentsanity's avatar

Laravel generate excel from query returns an error using maatwebsite

Basically i got a query and the results will be created as an excel file. Here is my code

$data = \DB::table('checkers')
        ->where('remarks_id',2)
        ->join('schedules','schedules.id','=','checkers.schedule_id')
        ->join('teachers','schedules.teacher_id','=','teachers.id')
        ->join('subject_codes','subject_codes.id','=','schedules.subject_code_id')
        ->join('remarks','remarks.id','=','checkers.remarks_id')
        ->where('checkers.created_at', '=>', $request->from)
        ->where('checkers.created_at', '=<', $request->to)
        ->select('teachers.fullname','subject_codes.subject_description','remarks.remarks_desc','checkers.created_at')
        ->get(); 

        $data = $data->map(function ($x) {
            return json_decode(json_encode($x), true);
        })->all();

        // dd($data);

        Excel::create('report', function($excel) use($data) {
            $excel->sheet('Sheetname', function($sheet) use($data) {
            });
        })->export('xls');

when i do `dd($data)

array:2 [
  0 => {#294
    +"fullname": "Edcel Pagagao"
    +"subject_description": "Capstone 1"
    +"remarks_desc": "No Teacher Around"
    +"created_at": "2020-01-30 00:00:00"
  }
  1 => {#298
    +"fullname": "Edcel Pagagao"
    +"subject_description": "Capstone 1"
    +"remarks_desc": "No Teacher Around"
    +"created_at": "2020-01-27 00:00:00"
  }
]

Which is what the docs said https://docs.laravel-excel.com/2.1/export/array.html based on 2.x version

But i still got error continue" targeting switch is equivalent to "break". Did you mean to use "continue 2

0 likes
3 replies

Please or to participate in this conversation.