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
@@ -16,14 +16,14 @@ $columns = [
16
16
'email'
17
17
];
18
18
19
-
$exporter = new Export(
20
-
User::query(),
21
-
$columns
22
-
);
19
+
$users = User::query(); // Query builder
23
20
24
-
$exporter->export();
21
+
Exporter::init($users, $columns, 'users.csv');
22
+
Exporter::export();
25
23
```
26
24
25
+
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.
26
+
27
27
**For eloquent relation**
28
28
```$xslt
29
29
$columns = [
@@ -43,3 +43,43 @@ $exporter->export();
43
43
```
44
44
45
45
Where `user` is the relation name, which is same as is in the `$columns` variable.
46
+
47
+
## Usage with raw PHP (PDOStatement)
48
+
49
+
Usage with PDO is straight forward. You **MUST** have to add the following code
50
+
```$xslt
51
+
$stmt->setFetchMode(PDO::FETCH_ASSOC); // N.B. must be included
52
+
```
53
+
54
+
And then pass the `$stmt` to `Exporter`
55
+
```$xslt
56
+
$servername = "localhost";
57
+
$username = "root";
58
+
$password = "password";
59
+
$dbname = "laravel";
60
+
61
+
$columns = [
62
+
'id',
63
+
'name',
64
+
'email'
65
+
];
66
+
67
+
try {
68
+
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
0 commit comments