質問編集履歴
1
test
CHANGED
File without changes
|
test
CHANGED
@@ -17,193 +17,3 @@
|
|
17
17
|
**UserExportAction.php**で取得した値をlaravelExcelを使用してCSV出力するにはどのように修正したら良いのでしょうか?
|
18
18
|
|
19
19
|
よろしくお願いいたします。
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
### 該当のソースコード
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
```ここに言語を入力
|
30
|
-
|
31
|
-
<?php
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
namespace App\UseCases\User;
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
use App\Constants\SystemSettings;
|
40
|
-
|
41
|
-
use App\Models\Search\SearchCondition;
|
42
|
-
|
43
|
-
use App\Models\User;
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
class UserExportAction
|
48
|
-
|
49
|
-
{
|
50
|
-
|
51
|
-
public function __invoke(SearchCondition $searchCondition)
|
52
|
-
|
53
|
-
{
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
$userCode = $searchCondition->get('user_code');
|
58
|
-
|
59
|
-
$userName = $searchCondition->get('user_name');
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
$query = User::query();
|
64
|
-
|
65
|
-
if (!is_null($userCode)) {
|
66
|
-
|
67
|
-
$query->where('user_code', 'LIKE', $userCode);
|
68
|
-
|
69
|
-
}
|
70
|
-
|
71
|
-
if (!is_null($menuName)) {
|
72
|
-
|
73
|
-
$query->where('user_name', 'LIKE', $menuName);
|
74
|
-
|
75
|
-
}
|
76
|
-
|
77
|
-
// 実際はもっと複雑な条件ですが省略しています
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
return $query->get();
|
82
|
-
|
83
|
-
}
|
84
|
-
|
85
|
-
}
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
```
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
```php
|
96
|
-
|
97
|
-
<?php
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
namespace App\Http\Controllers;
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
use App\Exports\UseruExport;
|
106
|
-
|
107
|
-
use App\Models\Search\SearchCondition;
|
108
|
-
|
109
|
-
use App\UseCases\User\UserExportAction;
|
110
|
-
|
111
|
-
use Illuminate\Http\Request;
|
112
|
-
|
113
|
-
use Maatwebsite\Excel\Excel;
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
class UserController extends Controller
|
118
|
-
|
119
|
-
{
|
120
|
-
|
121
|
-
public function userExport(UserExportAction $action, Request $request)
|
122
|
-
|
123
|
-
{
|
124
|
-
|
125
|
-
$searchCondition = new SearchCondition($request->session()->get(config('session.key.search.user'));
|
126
|
-
|
127
|
-
$users = $action($searchCondition);
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
//$usersをUserExportクラスに渡したい
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
return Excel::download(new UserExport, 'user.csv');
|
136
|
-
|
137
|
-
}
|
138
|
-
|
139
|
-
}
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
```
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
```php
|
148
|
-
|
149
|
-
<?php
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
namespace App\Exports;
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
use Maatwebsite\Excel\Concerns\FromCollection;
|
158
|
-
|
159
|
-
use Maatwebsite\Excel\Concerns\WithHeadings;
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
class UserExport implements FromCollection, WithHeadings
|
164
|
-
|
165
|
-
{
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
/**
|
170
|
-
|
171
|
-
* @return \Illuminate\Support\Collection
|
172
|
-
|
173
|
-
*/
|
174
|
-
|
175
|
-
public function collection()
|
176
|
-
|
177
|
-
{
|
178
|
-
|
179
|
-
//
|
180
|
-
|
181
|
-
}
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
/**
|
186
|
-
|
187
|
-
* @return array
|
188
|
-
|
189
|
-
*/
|
190
|
-
|
191
|
-
public function headings() :array
|
192
|
-
|
193
|
-
{
|
194
|
-
|
195
|
-
return [
|
196
|
-
|
197
|
-
'ID','CODE','NAME'
|
198
|
-
|
199
|
-
];
|
200
|
-
|
201
|
-
}
|
202
|
-
|
203
|
-
}
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
```
|