Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation: What's about records count limitation #21

Closed
saidbakr opened this issue Dec 5, 2017 · 3 comments
Closed

Documentation: What's about records count limitation #21

saidbakr opened this issue Dec 5, 2017 · 3 comments

Comments

@saidbakr
Copy link

saidbakr commented Dec 5, 2017

In the documentation there is no any hint or mention about exporting large models. For example, suppose User model with more than 40K users and we want to export, id, name, email, age, address and salary.
How could the package deals with memory limitation and processing time?

@usmanhalalit
Copy link
Owner

@saidbakr You can stream the output, you can pass a stream writer in the constructor.

https://github.com/usmanhalalit/laracsv/blob/master/src/Laracsv/Export.php#L33
http://csv.thephpleague.com/8.0/instantiation/#abstractcsvcreatefromstream

@delmicio
Copy link

@usmanhalalit can you please provide an example of stream with your lib?

use League\Csv\Writer;

$writer = Writer::createFromStream(fopen('php://output', 'w'));
$csvExporter = new \Laracsv\Export($writer);
$users = User::get();

// Register the hook before building
$csvExporter->beforeEach(function ($user) {
    $user->created_at = date('f', strtotime($user->created_at)); 
});

$csvExporter->build($users, ['email', 'name' => 'Full Name', 'created_at' => 'Joined']);

Is this the correct approach?

@usmanhalalit
Copy link
Owner

@delmicio yes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants