首页 > 解决方案 > Maatwebsite 没有在 laravel 中获取关系表的数据

问题描述

我正在尝试使用 maatwebsite 导出 csv 文件。我写的查询正在获取与它有关系的其他表的数据。但它仅使用一个表数据导出 csv 文件。


    $data = SaleOrder::where('id',$id)->with('customers')->get()->toArray();


    return Excel::create('Packlist Sale Order '.$id, function($excel) use ($data) {
            $excel->sheet('mySheet', function($sheet) use ($data)
            {

        $sheet->fromArray($data);
        foreach($data as $customer)
        {

          $sheet->fromArray($customer['customers']);

        }

    })->download('xlsx');

我想在 csv 文件中获取两个表的数据

标签: laravelcsvlaravel-5maatwebsite-excel

解决方案


推荐阅读