从控制器Laravel导出CSV

时间:2019-05-09 06:04:03

标签: laravel csv controller

如何从控制器而不是从数据库导出查询以及从控制器导出结果数据?

例如:

switch ($tipe) {

            case 'car':

            $totaldata2 =  \DB::select(\DB::raw("
                SELECT $flag as label,
                COUNT(tr.id) as data
                FROM driver tr
                LEFT JOIN vw_driver vw ON vw.id = tr.id
                WHERE tr.service= 'C'
                $where 
                GROUP BY $flag
                ORDER BY $flag asc
                "));

我希望从上面的结果数据中导出的CSV是

period_count,"status_label","status_data","service_label","service_data"

1 个答案:

答案 0 :(得分:0)

此软件包是使用Laravel导入/导出数据的最佳工具,请检查以下内容:

https://laravel-excel.com/