【问题标题】:Get an error: Object of class stdClass could not be converted to string when export to excel using maatwebsite报错:使用 maatwebsite 导出到 excel 时,stdClass 类的对象无法转换为字符串
【发布时间】:2017-08-29 01:20:33
【问题描述】:

我想显示三个表,三个表稍后要导出,但是我在这里遇到了问题,请帮我解决我的问题。 谢谢。

public function downloadExcel($type)
{
     $data = DB::table('tb_siswa')
            ->join('tb_ayah', 'tb_siswa.id', '=', 'tb_ayah.id_siswa')
            ->join('tb_ibu', 'tb_siswa.id', '=', 'tb_ibu.id_siswa')
            ->select('tb_siswa.nm_lengkap', 'tb_ayah.nm_ayah', 'tb_ibu.nm_ibu')
            ->get();   
    return Excel::create('Data siswa', function($excel) use ($data) {
        $excel->sheet('datasiswa', function($sheet) use ($data)
        {
            $sheet->fromArray($data);
        });
    })->download($type);
}

【问题讨论】:

  • 哪一行产生了错误?

标签: sql arrays laravel eloquent maatwebsite-excel


【解决方案1】:

在返回函数前添加这一行

$data= json_decode( json_encode($data), true);

希望对你有帮助!

【讨论】:

    猜你喜欢
    • 2018-10-19
    • 2021-05-28
    • 2013-07-03
    • 2014-11-21
    • 2011-04-06
    相关资源
    最近更新 更多