vitorccs / laravel-csv

PHP Laravel package to export and import CSV files in a memory-optimized way
MIT License
26 stars 5 forks source link

Declaration of App\Exports\PostsFromCollection::collection() must be compatible with Vitorccs\LaravelCsv\Concerns\FromCollection::collection(): Illuminate\Support\Collection #1

Closed seabasss closed 2 years ago

seabasss commented 2 years ago

Thanks, this package looks great!

I can't figure out how to use the FromCollection feature. It's the only one without any examples. I'm trying this:

public function collection()
{
    return Post::all();
}

But I'm getting this:

Declaration of App\Exports\PostsFromCollection::collection() must be compatible with Vitorccs\LaravelCsv\Concerns\FromCollection::collection(): Illuminate\Support\Collection

Ideas? Thank you!

seabasss commented 2 years ago

Fixed it:

public function collection(): Collection
{
    return Post::all();
}

Minor detail. The example page say public function query();. This should be public function query() right?

vitorccs commented 2 years ago

Hi @seabasss

Thanks for the feedback.

That's correct - it should be public function query without the semicolon ;.

I have just fixed the README file and also added a new section "Data sources" with more samples: https://github.com/vitorccs/laravel-csv#data-sources

seabasss commented 2 years ago

Hi @seabasss

Thanks for the feedback.

That's correct - it should be public function query without the semicolon ;.

I have just fixed the README file and also added a new section "Data sources" with more samples: https://github.com/vitorccs/laravel-csv#data-sources

Amazing! Thank you so much! Exports are working great!