0
votes

I was trying to export a query - the function in the controller was as below

class Export implements FromCollection
{
    public function collection()
    {
        $data = DB::table('Providers')->get();

        return $data;
    }
}

but producing the error:

vendor\phpoffice\phpspreadsheet\src\PhpSpreadsheet\Cell\DefaultValueBinder.php

enter image description here

"Object of class stdClass could not be converted to string"

3
Please show some of the stack trace of the error.Camilo
Hello @Camilo I updated the post, thaks for you comment.CADAVID

3 Answers

1
votes

You could try to make a collection out of it and then map it.

$dataArray = collect($data)->map( function($stdClass) {

    return (array) stdClass;
}

Not sure what your data looks like, perhaps you could also cast it to a string. Hope this helps.

1
votes
class Export implements FromCollection
{
    public function collection()
    {
        $data = DB::table('Providers')->get();
        $data = $data->toArray();
        $data = json_decode(json_encode($data), true);
        return $data;
    }
}
-4
votes

You Can Do It Like This

class Export implements FromCollection
{
    public function collection()
    {
        $data = DB::table('Providers')->get();
        return $data->toJson();
        return $data->toArray();
    }
}