質問編集履歴

9

疑問の修正

2017/07/28 00:13

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -4,9 +4,13 @@
4
4
 
5
5
  具体的には、1列目に入るべき値が2列目に入ってしまっています。
6
6
 
7
+ また、一部こちらが望んだ並び順ではない並び順が出力されます。
8
+
9
+ CSVに出力されるものの並び順を確認するためにはどこをみればよいのでしょうか?
7
10
 
8
11
 
12
+
9
- この問題を解決するためにご助力いただけないでしょうか。
13
+ れらの問題を解決するためにご助力いただけないでしょうか。
10
14
 
11
15
 
12
16
 

8

タイトルの修正

2017/07/28 00:13

投稿

退会済みユーザー
test CHANGED
@@ -1 +1 @@
1
- 【laravel】csvに出力する際に、必ず1列目で空欄入っしまう
1
+ 【laravel】csvに出力する際に、出力される値の位置ズレいるものがある
test CHANGED
File without changes

7

「追記」を修正いたしました。

2017/07/27 08:03

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -148,9 +148,13 @@
148
148
 
149
149
  4 => "D'"
150
150
 
151
- 5 => "E'"
151
+ 5 => "F'"
152
152
 
153
- 6 => "F'"
153
+ 6 => "G'"
154
+
155
+
156
+
157
+ ※一部合致している箇所と、合致していない箇所がある状況にあります。
154
158
 
155
159
  ```
156
160
 

6

情報の修正②

2017/07/27 07:34

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -14,27 +14,7 @@
14
14
 
15
15
 
16
16
 
17
- ###発生している問題・エラーメッセージ
18
-
19
-
20
-
21
- ```
22
-
23
- 1 => array:2 [▼
24
-
25
- 0 => null
26
-
27
- 1 => "〇〇"
28
-
29
- ]
30
-
31
- ```
32
-
33
-
34
-
35
17
  ###該当のソースコード
36
-
37
- dd($value)
38
18
 
39
19
  ```php
40
20
 

5

依然として不明なため、情報の追加

2017/07/27 07:13

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -86,15 +86,95 @@
86
86
 
87
87
  ```
88
88
 
89
+
90
+
91
+ ###追記
92
+
93
+ CSVの中身を確認しましたら、(1行目を除く)全ての1列目に入れるもののみ、全ての2列目に入っておりました。
94
+
95
+ その原因は、1列目と2列目のそれぞれのセルに該当する値を挿入するための指標であるvalueが同じ値であったためだと考えております。
96
+
89
97
  ```php
90
98
 
91
- public function titlesValuess($type, $ids, $items) {
99
+ public function titlesValuess($type, $ids, $items) {
92
100
 
93
- return [$titles, $value];
101
+ $info = $this->info()[$type];
94
102
 
103
+ $komoji = substr($type, 0, 1);
104
+
105
+ $titles = [];
106
+
107
+ $data = [];
108
+
109
+ if (request()->input($komoji.'item')) {
110
+
111
+ $input = array_unique(array_map('intval',(array)request()->input($komoji.'item')));
112
+
113
+ foreach ($items as $i => $item) {
114
+
115
+ if (in_array($item['id'], $input, true)) {
116
+
117
+ $titles[] = $item['name'];
118
+
119
+ $item['index'] = count($titles) - 1;
120
+
121
+ $data['item'][$item['id']] = $item;
122
+
95
- }
123
+ }
124
+
125
+ }
126
+
127
+ }
128
+
129
+ if (!$titles) return [$titles, []];
130
+
131
+ $valuess = array_fill_keys($ids, array_fill(0, count($titles), null));
132
+
133
+ return [$titles, $valuess];
134
+
135
+ }
96
136
 
97
137
  ```
138
+
139
+ ```
140
+
141
+ titlesValuessの$titlesにdd
142
+
143
+ array:5 [▼
144
+
145
+ 0 => "A"
146
+
147
+ 1 => "B"
148
+
149
+ 2 => "C"
150
+
151
+ 3 => "D"
152
+
153
+ 4 => "E"
154
+
155
+ 5 => "F"
156
+
157
+
158
+
159
+ titlesValuessの$valuessにdd
160
+
161
+ 0 => null
162
+
163
+ 1 => "A'"
164
+
165
+ 2 => "B'"
166
+
167
+ 3 => "C'"
168
+
169
+ 4 => "D'"
170
+
171
+ 5 => "E'"
172
+
173
+ 6 => "F'"
174
+
175
+ ```
176
+
177
+
98
178
 
99
179
 
100
180
 

4

誤解を招く文章を修正

2017/07/27 07:12

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -1,6 +1,6 @@
1
1
  ###前提・実現したいこと
2
2
 
3
- csvをDLしようとする際、必ず出力されるCSVの第一行目が空になってしまいます。
3
+ csvをDLしようとする際、必ず出力されるCSVの1行目を除く他すべての1列目が空になってしまいます。
4
4
 
5
5
  具体的には、1列目に入るべき値が2列目に入ってしまっています。
6
6
 

3

修正

2017/07/26 06:02

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -34,6 +34,8 @@
34
34
 
35
35
  ###該当のソースコード
36
36
 
37
+ dd($value)
38
+
37
39
  ```php
38
40
 
39
41
  list ($titles, $value) = $this->titlesValue($type, $ids, $items);
@@ -68,7 +70,7 @@
68
70
 
69
71
  ```
70
72
 
71
- ```
73
+ ```php
72
74
 
73
75
  public function main($type) {
74
76
 
@@ -84,11 +86,11 @@
84
86
 
85
87
  ```
86
88
 
87
- ```
89
+ ```php
88
90
 
89
91
  public function titlesValuess($type, $ids, $items) {
90
92
 
91
- return [$titles, $valuess];
93
+ return [$titles, $value];
92
94
 
93
95
  }
94
96
 
@@ -100,6 +102,8 @@
100
102
 
101
103
  listのあるところで「dd($value);」をかけてみたところ、上記の配列が結果として出てきました。
102
104
 
105
+ また、「dd($titles);」ではCSVに出力される最初の行にあたる項目名が出力されます。
106
+
103
107
 
104
108
 
105
109
  ###補足情報(言語/FW/ツール等のバージョンなど)

2

修正

2017/07/26 03:57

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -44,7 +44,7 @@
44
44
 
45
45
  } while (file_exists($csvPath));
46
46
 
47
- $buf = fopen($csvPath, 'w');
47
+ $buf = fopen($csv, 'w');
48
48
 
49
49
  fwrite($buf, "\xEF\xBB\xBF");
50
50
 
@@ -60,7 +60,37 @@
60
60
 
61
61
  }
62
62
 
63
- fclose($buf);
63
+ fclose($buf);
64
+
65
+ $file = (string)request()->input('file');
66
+
67
+ return response()->download($csvPath, ($file!==''?$file:'export').'.csv')->deleteFileAfterSend(true);
68
+
69
+ ```
70
+
71
+ ```
72
+
73
+ public function main($type) {
74
+
75
+ $komoji = substr($type, 0, 1);
76
+
77
+ $ids = $this->ids($type);
78
+
79
+ $items = array_map(function($c){return $c->toArray();}, call_user_func('\\App\\Models\\'.strtoupper($komoji).'item::uses'));
80
+
81
+ return $this->download($type, $ids, $items);
82
+
83
+ }
84
+
85
+ ```
86
+
87
+ ```
88
+
89
+ public function titlesValuess($type, $ids, $items) {
90
+
91
+ return [$titles, $valuess];
92
+
93
+ }
64
94
 
65
95
  ```
66
96
 
@@ -68,7 +98,7 @@
68
98
 
69
99
  ###試したこと
70
100
 
71
- listのあるところで「dd($value);」をかけてみたとこえ¥
101
+ listのあるところで「dd($value);」をかけてみたところ、上記の配列が結果として出てきました。
72
102
 
73
103
 
74
104
 

1

更新

2017/07/26 03:52

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -10,7 +10,7 @@
10
10
 
11
11
 
12
12
 
13
- よろしくお願いいたします。
13
+ 何卒よろしくお願いいたします。
14
14
 
15
15
 
16
16