laravel – Object of class stdClass could not be converted to string Maatwebsite

laravel – Object of class stdClass could not be converted to string Maatwebsite

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.

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

laravel – Object of class stdClass could not be converted to string Maatwebsite

You Can Do It Like This

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

Leave a Reply

Your email address will not be published. Required fields are marked *