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