Skip to content

Commit 7caba2a

Browse files
committed
Adds new section "Data sources" to README file
1 parent a3911a2 commit 7caba2a

File tree

1 file changed

+89
-3
lines changed

1 file changed

+89
-3
lines changed

README.md

Lines changed: 89 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ Generate CSV files from any of these data sources: _PHP arrays_, _Laravel Collec
66

77
This project was inspired on https://github.com/maatwebsite/Laravel-Excel which is a great project and can handle many formats (Excel, PDF, OpenOffice and CSV). But since it uses PhpSpreadsheet, it is not optimized for exporting large CSV files (thousands of records) causing the PHP memory exhaustion.
88

9-
The memory usage is optimized in this project by retrieving small chunks of results at a time and outputting the CSV content directly to the client browser or to a persistent with the use of [PHP streams](https://www.php.net/manual/en/intro.stream.php).
9+
The memory usage is optimized in this project by retrieving small chunks of results at a time and outputting the CSV content directly to the client browser or to a persistent file with the use of [PHP streams](https://www.php.net/manual/en/intro.stream.php).
1010

11-
This project is using some of Laravel-Excel design principles because it is both a solid work and a reference, and by doing that, it also reduces the learning curve and adaption to this library.
11+
This project is using some of Laravel-Excel design principles because it is both a solid work and a reference, and by doing that, it also reduces the learning curve and adoption to this library.
1212

1313
# Requirements
1414
* PHP >= 7.4
@@ -42,7 +42,7 @@ class UsersExport implements FromQuery
4242
{
4343
use Exportable;
4444

45-
public function query();
45+
public function query()
4646
{
4747
return User::query();
4848
}
@@ -76,6 +76,92 @@ $filename = CsvHelper::filename();
7676
]);
7777
```
7878

79+
# Data sources
80+
81+
## Laravel Eloquent Query Builder
82+
```php
83+
namespace App\Exports;
84+
85+
use App\User;
86+
use Vitorccs\LaravelCsv\Concerns\Exportable;
87+
use Vitorccs\LaravelCsv\Concerns\FromQuery;
88+
89+
class MyQueryExport implements FromQuery
90+
{
91+
use Exportable;
92+
93+
public function query()
94+
{
95+
return User::query();
96+
}
97+
}
98+
```
99+
100+
## Laravel Database Query Builder
101+
```php
102+
namespace App\Exports;
103+
104+
use App\User;
105+
use Vitorccs\LaravelCsv\Concerns\Exportable;
106+
use Vitorccs\LaravelCsv\Concerns\FromQuery;
107+
use Illuminate\Support\Facades\DB;
108+
109+
class MyQueryExport implements FromQuery
110+
{
111+
use Exportable;
112+
113+
public function query()
114+
{
115+
return DB::table('users');
116+
}
117+
}
118+
```
119+
120+
## Laravel Collection
121+
```php
122+
namespace App\Exports;
123+
124+
use Illuminate\Support\Collection;
125+
use Vitorccs\LaravelCsv\Concerns\Exportable;
126+
use Vitorccs\LaravelCsv\Concerns\FromCollection;
127+
128+
class MyCollectionExport implements FromCollection
129+
{
130+
use Exportable;
131+
132+
public function collection(): Collection
133+
{
134+
return collect([
135+
['a1', 'b1', 'c1'],
136+
['a2', 'b2', 'c2'],
137+
['a3', 'b3', 'c3']
138+
]);
139+
}
140+
}
141+
```
142+
143+
## PHP Arrays
144+
```php
145+
namespace App\Exports;
146+
147+
use Vitorccs\LaravelCsv\Concerns\Exportable;
148+
use Vitorccs\LaravelCsv\Concerns\FromArray;
149+
150+
class MyArrayExport implements FromArray
151+
{
152+
use Exportable;
153+
154+
public function array(): array
155+
{
156+
return [
157+
['a1', 'b1', 'c1'],
158+
['a2', 'b2', 'c2'],
159+
['a3', 'b3', 'c3']
160+
];
161+
}
162+
}
163+
```
164+
79165
# Implementations
80166

81167
## Headings

0 commit comments

Comments
 (0)