public function exportExcel(){
Excel::create('订单统计'.date('Y-m-d H_i_s'), function ($excel) {
$excel->sheet('order', function ($sheet) {
$data = Orders::where('type',2)->orderby('id','desc')->get(); //要用get()
$sheet->appendRow(['老师姓名','联系方式','老师性别']);//这里是表头的名称
foreach($data as $o){ //appendRow是导出一行,要导出数据表就要循环这个
$sheet->appendRow([$o->teacher_name,(string)$o->teacher_mobile,$o->teacher_sex]);//进行循环
}
});
})->download('csv');
}
网友评论