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);
});
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
Most helpful comment
See documentation: https://docs.laravel-excel.com/3.1/imports/basics.html#importing-to-array-or-collection