Get an error: Object of class stdClass could not be converted to string when export to excel using maatwebsite

Get an error: Object of class stdClass could not be converted to string when export to excel using maatwebsite

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

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);
}

在return函数前添加这一行

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

希望对您有所帮助!