Laravel-excel: [QUESTION] got Response::setContent() must be of the type string or null, object given

Created on 15 Jul 2020  路  4Comments  路  Source: Maatwebsite/Laravel-Excel

Prerequisites

Versions

  • PHP version: 7.4.7
  • Laravel version: 7.20.0
  • Package version: 3.1.19

Description

I got TypeError: Argument 1 passed to Symfony\Component\HttpFoundation\Response::setContent() must be of the type string or null, object given, called in myprojectpath/vendor/laravel/framework/src/Illuminate/Http/Response.php on line 65 in file myprojectpath/vendor/symfony/http-foundation/Response.php on line 412

class MyImports implements ToCollection
{
    public function collection(Collection $collection)
    {
        return $collection;
    }
}
Route::get('apireadpdf', function () {
    $myFile = public_path("my-excel.xlsx");
    $a = \Maatwebsite\Excel\Facades\Excel::import(new \App\Imports\MyImports(), $myFile);
    return response($a);
});
question

Most helpful comment

See documentation: https://docs.laravel-excel.com/3.1/imports/basics.html#importing-to-array-or-collection

All 4 comments

Can you explain what you are trying to achieve? I'm not sure based on your example. The collection() method doesn't return anything.

I only want to read a .xlsx file to be an array

See documentation: https://docs.laravel-excel.com/3.1/imports/basics.html#importing-to-array-or-collection

thank you. it works

Was this page helpful?
0 / 5 - 0 ratings