You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+45-5Lines changed: 45 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,14 +19,14 @@ $columns = [
19
19
'email'
20
20
];
21
21
22
-
$exporter = new Export(
23
-
User::query(), // Query Builder
24
-
$columns
25
-
);
22
+
$users = User::query(); // Query builder
26
23
27
-
$exporter->export();
24
+
Exporter::init($users, $columns, 'users.csv');
25
+
Exporter::export();
28
26
```
29
27
28
+
Or you can pass `Collection` or `Array`. But it is **highly recommended** to pass the **`Query Builder`** as it will use generator to save memory usage.
29
+
30
30
**For eloquent relation**
31
31
```$xslt
32
32
$columns = [
@@ -46,3 +46,43 @@ $exporter->export();
46
46
```
47
47
48
48
Where `user` is the relation name, which is same as is in the `$columns` variable.
49
+
50
+
## Usage with raw PHP (PDOStatement)
51
+
52
+
Usage with PDO is straight forward. You **MUST** have to add the following code
53
+
```$xslt
54
+
$stmt->setFetchMode(PDO::FETCH_ASSOC); // N.B. must be included
55
+
```
56
+
57
+
And then pass the `$stmt` to `Exporter`
58
+
```$xslt
59
+
$servername = "localhost";
60
+
$username = "root";
61
+
$password = "password";
62
+
$dbname = "laravel";
63
+
64
+
$columns = [
65
+
'id',
66
+
'name',
67
+
'email'
68
+
];
69
+
70
+
try {
71
+
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
0 commit comments