回答編集履歴
2
不要なコメントの削除
test
CHANGED
@@ -74,8 +74,6 @@
|
|
74
74
|
|
75
75
|
*
|
76
76
|
|
77
|
-
* @author Enomoto Yousuke
|
78
|
-
|
79
77
|
*/
|
80
78
|
|
81
79
|
class TestExcel implements FromQuery {
|
1
誤った回答を修正
test
CHANGED
@@ -1,6 +1,106 @@
|
|
1
|
-
|
1
|
+
他の回答者様の内容にありますが、From Queryの場合は自動でChunkが適用されます。下記の様に書く事で正常に動作しました。ちなみに、chunkの件数は、`config/excel.php`で定義されています。
|
2
2
|
|
3
|
+
[公式サイト](https://laravel-excel.maatwebsite.nl/docs/3.0/export/from-query)
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
### Controller側
|
8
|
+
|
9
|
+
```php
|
10
|
+
|
11
|
+
<?php
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
namespace App\Http\Controllers;
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
use Illuminate\Http\Request;
|
20
|
+
|
21
|
+
use App\Test\TestExcel;
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
class homeController extends Controller
|
26
|
+
|
27
|
+
{
|
28
|
+
|
29
|
+
public function index(Request $request) {
|
30
|
+
|
31
|
+
return (new TestExcel())->download('test.xlsx');
|
32
|
+
|
33
|
+
}
|
34
|
+
|
35
|
+
}
|
36
|
+
|
37
|
+
```
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
### 抽出処理
|
42
|
+
|
43
|
+
```php
|
44
|
+
|
45
|
+
<?php
|
46
|
+
|
47
|
+
namespace App\Test;
|
48
|
+
|
49
|
+
/*
|
50
|
+
|
51
|
+
* To change this license header, choose License Headers in Project Properties.
|
52
|
+
|
53
|
+
* To change this template file, choose Tools | Templates
|
54
|
+
|
55
|
+
* and open the template in the editor.
|
56
|
+
|
57
|
+
*/
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
use Maatwebsite\Excel\Concerns\FromQuery;
|
62
|
+
|
63
|
+
use Maatwebsite\Excel\Concerns\Exportable;
|
64
|
+
|
65
|
+
use App\User;
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
/**
|
72
|
+
|
73
|
+
* Description of TestExcel
|
74
|
+
|
75
|
+
*
|
76
|
+
|
77
|
+
* @author Enomoto Yousuke
|
78
|
+
|
79
|
+
*/
|
80
|
+
|
81
|
+
class TestExcel implements FromQuery {
|
82
|
+
|
83
|
+
use Exportable;
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
public function query(){
|
88
|
+
|
89
|
+
//get()は不要なので要注意!
|
90
|
+
|
91
|
+
return User::orderBy('id', 'DESC');
|
92
|
+
|
93
|
+
}
|
94
|
+
|
95
|
+
}
|
96
|
+
|
97
|
+
```
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
## (こちらの情報は古いバージョンの為、3.0には適用できません)
|
102
|
+
|
3
|
-
[参考サイト](https://github.com/Maatwebsite/Laravel-Excel/issues/1079)
|
103
|
+
若干、古いバージョンのIssueですが~~下記が参考になるのではないでしょうか?~~[参考サイト](https://github.com/Maatwebsite/Laravel-Excel/issues/1079)
|
4
104
|
|
5
105
|
|
6
106
|
|