Как исправить «Объект класса stdClass не может быть преобразован в строку»: Laravel 5.4 - PullRequest
0 голосов
/ 15 апреля 2019

У меня проблема, когда я пытаюсь сгенерировать данные из базы данных, используя maatwebsite / laravel-excel в .csv, я получаю ошибку, подобную этой: Объект класса stdClass не может быть преобразован в строку.

Иногда, когда я выбираю данные из базы данных, используя только одно поле, файл может генерировать (.csv).Это моя ошибка:

в HandleExceptions-> handleError (4096, «Объект класса stdClass не может быть преобразован в строку», / vendor / phpoffice / phpexcel / Classes / PHPExcel / Cell / DefaultValueBinder.php ', 65, array (' cell '=> object (PHPExcel_Cell),' value '=> object (stdClass)))

Это мой запрос для получения данных из базы данных, var $temp для размещения результатов запроса.

    public function coba ($type){
        $temp = DB::select(DB::raw("select regionalid, 
        nvl(sum(case when lastactiontype='0' then totalcharge end),0) as creditlimit_usage,
        count(case when lastactiontype='0' then msisdn end) as creditlimit_rec,
        nvl(sum(case when lastactiontype='1' then totalcharge end),0) as blocked_usage,
        count(case when lastactiontype='1' then msisdn end) as blocked_rec,
        nvl(sum(case when lastactiontype='2' then totalcharge end),0) as adjusted_usage,
        count(case when lastactiontype='2' then msisdn end) as adjusted_rec,
        nvl(sum(case when lastactiontype='3' then totalcharge end),0) as sms_usage, 
        count(case when lastactiontype='3' then msisdn end) as sms_rec,
        nvl(sum(case when lastactiontype='5' then totalcharge end),0) as call_usage, 
        count(case when lastactiontype='5' then msisdn end) as call_rec,
        nvl(sum(case when lastactiontype in ('1','2','3','5') then totalcharge end),0) as total_usage, 
        count(case when lastactiontype in ('1','2','3','5') then msisdn end) as total_rec
    from alarms_v2
    where alarmdate = '$today'
    group by regionalid order by regionalid"));

    return Excel::create('datadoc', function ($excel) use ($temp) {
        $excel->sheet('mySheet', function ($sheet) use ($temp) {
            $sheet->fromArray($temp);
        });
    })->download($type);

Я ожидаю, что смогу сгенерировать данные из базы данных в .csv или превзойти их в работе.

1 Ответ

0 голосов
/ 15 апреля 2019

Попробуйте это:

$sheet->fromArray((array)$temp);
...