Skip to content

How to create a plain excel file for testing? #4074

Discussion options

You must be logged in to vote

but this one expects an Object / my Import Class - but why?

I don't recommend handling export logic outside of an export class in case of actual business logic. In my professional opinion it's a lot better to encapsulate it.

I just want to pass an array and say "hey, this is the excel I need and I want to upload this one now". Do you have any tips?

There are three ways to do what you want:

Have some generic class

Excel::store(new ArrayExport($data))

Anonymous classes:

Excel::store(new class implements FromArray {

// have a constructor and array method etc.

})

Using the collection macro (https://docs.laravel-excel.com/3.1/exports/collection.html#collection-macros)

collect($data)->s…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@torbentschechne
Comment options

Answer selected by torbentschechne
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants