質問編集履歴
5
修正
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
laravel5
|
1
|
+
laravel5 取得した値をviewに表示させたい
|
test
CHANGED
@@ -1,257 +1,5 @@
|
|
1
|
-
|
1
|
+
laravel5 取得した値をviewに表示させたい
|
2
|
-
|
3
|
-
コントローラーから現行データと最新データをviewへ渡し、foreachで取り出して項目ごとに表として出すところでエラーが出てつまづいています。
|
4
2
|
|
5
3
|
|
6
4
|
|
7
|
-
エラー内容は以下です。
|
8
|
-
|
9
|
-
Trying to get property of non-object (View:
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
調べてみたら変数の中身が空になっていることが原因であることはわかりました。
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
コントローラー部分でのsolrからデータを受け取ることは出来ています。
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
laravel5.3です。
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
コントローラーからviewへ渡してforeachで項目ごとに並べるにはどのようにしたらよろしいでしょうか。
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
教えてください。お願い致します。
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
foreachで表示させる参考URL
|
34
|
-
|
35
|
-
http://qiita.com/ryo2132/items/63ced19601b3fa30e6de
|
36
|
-
|
37
|
-
http://kotori-blog.com/php/foreach_error/
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
```lang-php
|
42
|
-
|
43
|
-
<!DOCTYPE html>
|
44
|
-
|
45
|
-
<html>
|
46
|
-
|
47
|
-
<head>
|
48
|
-
|
49
|
-
<!-- CSSを追加 -->
|
50
|
-
|
51
|
-
<link rel="stylesheet" type="text/css" href="/css/style.css">
|
52
|
-
|
53
|
-
<meta charset="UTF-8">
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
</head>
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
<body>
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
<h1>POIクローリング</h1>
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
<label>検索クエリ</label>
|
72
|
-
|
73
|
-
<form action="/search" method="get">
|
74
|
-
|
75
|
-
<input type="text" name="keyword">
|
76
|
-
|
77
|
-
<input type="hidden" name="_token" value="<?php echo csrf_token(); ?>">
|
78
|
-
|
79
|
-
<input type="submit">
|
80
|
-
|
81
|
-
</form>
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
<table class="type01">
|
86
|
-
|
87
|
-
<tbody>
|
88
|
-
|
89
|
-
<tr>
|
90
|
-
|
91
|
-
<th class="r1"></th>
|
92
|
-
|
93
|
-
<th class="r2">現行版</th>
|
94
|
-
|
95
|
-
<th class="r3">改良版</th>
|
96
|
-
|
97
|
-
</tr>
|
98
|
-
|
99
|
-
@foreach((array)$before_content as $recode)
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
<tr>
|
104
|
-
|
105
|
-
<th class="r1">PKID</th>
|
106
|
-
|
107
|
-
<td class="r2">{{$recode->PKID or""}}</td>
|
108
|
-
|
109
|
-
<td class="r3">改良版POIDの中身</td>
|
110
|
-
|
111
|
-
</tr>
|
112
|
-
|
113
|
-
<tr>
|
114
|
-
|
115
|
-
<th class="r1">ID</th>
|
116
|
-
|
117
|
-
<td class="r2">現行版IDの中身</td>
|
118
|
-
|
119
|
-
<td class="r3">改良版IDの中身</td>
|
120
|
-
|
121
|
-
</tr>
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
</tbody>
|
126
|
-
|
127
|
-
@endforeach
|
128
|
-
|
129
|
-
</table>
|
130
|
-
|
131
|
-
<!-- Scripts --><!-- ③ 追加 -->
|
132
|
-
|
133
|
-
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
|
134
|
-
|
135
|
-
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
</body>
|
140
|
-
|
141
|
-
</html>
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
```
|
148
|
-
|
149
|
-
```lang-php
|
150
|
-
|
151
|
-
|
5
|
+
削除しました。
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
namespace App\Http\Controllers;
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
use Illuminate\Http\Request;
|
160
|
-
|
161
|
-
use Auth;
|
162
|
-
|
163
|
-
use App\Http\Requests;
|
164
|
-
|
165
|
-
use Search;
|
166
|
-
|
167
|
-
use JmesPath;
|
168
|
-
|
169
|
-
use Input;
|
170
|
-
|
171
|
-
class SearchController extends Controller
|
172
|
-
|
173
|
-
{
|
174
|
-
|
175
|
-
public function index(Request $request)
|
176
|
-
|
177
|
-
{ //キーワード受け取り
|
178
|
-
|
179
|
-
$keyword = Input::get('keyword');
|
180
|
-
|
181
|
-
var_dump($keyword);
|
182
|
-
|
183
|
-
$before_url = "solrからのURL"
|
184
|
-
|
185
|
-
$after_url ="solrからのUR";
|
186
|
-
|
187
|
-
//var_dump($before_url);exit;
|
188
|
-
|
189
|
-
$before_content = file_get_contents($before_url);
|
190
|
-
|
191
|
-
$after_content = file_get_contents($after_url);
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
// evalダメ、良くないけど、画面イメージ伝えるのでとりあえず使う
|
196
|
-
|
197
|
-
eval('$before_response = '. $before_content. ';');
|
198
|
-
|
199
|
-
eval('$after_response = '. $after_content. ';');
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
$before_content = json_encode($before_response);
|
204
|
-
|
205
|
-
$after_content = json_encode($before_response);
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
$before_hitcount = JmesPath\search('response.numFound', $before_response);
|
210
|
-
|
211
|
-
$after_hitcount = JmesPath\search('response.numFound', $after_response);
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
$query = 'response.docs[].
|
216
|
-
|
217
|
-
{
|
218
|
-
|
219
|
-
PKID: PKID,
|
220
|
-
|
221
|
-
id: v_str_id,
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
}';
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
// JmesPathはPHP配列を戻す
|
230
|
-
|
231
|
-
$before_content = json_encode(
|
232
|
-
|
233
|
-
JmesPath\search($query, $before_response),
|
234
|
-
|
235
|
-
JSON_UNESCAPED_UNICODE|JSON_PRETTY_PRINT
|
236
|
-
|
237
|
-
);
|
238
|
-
|
239
|
-
$after_content = json_encode(
|
240
|
-
|
241
|
-
JmesPath\search($query, $after_response),
|
242
|
-
|
243
|
-
JSON_UNESCAPED_UNICODE|JSON_PRETTY_PRINT
|
244
|
-
|
245
|
-
);
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
return view('scraper', compact('before_content', 'after_content'));
|
250
|
-
|
251
|
-
}
|
252
|
-
|
253
|
-
}
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
```
|
4
サイト追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -34,6 +34,8 @@
|
|
34
34
|
|
35
35
|
http://qiita.com/ryo2132/items/63ced19601b3fa30e6de
|
36
36
|
|
37
|
+
http://kotori-blog.com/php/foreach_error/
|
38
|
+
|
37
39
|
|
38
40
|
|
39
41
|
```lang-php
|
3
誤字
test
CHANGED
File without changes
|
test
CHANGED
@@ -100,9 +100,9 @@
|
|
100
100
|
|
101
101
|
<tr>
|
102
102
|
|
103
|
-
<th class="r1">P
|
103
|
+
<th class="r1">PKID</th>
|
104
|
-
|
104
|
+
|
105
|
-
<td class="r2">{{$recode->P
|
105
|
+
<td class="r2">{{$recode->PKID or""}}</td>
|
106
106
|
|
107
107
|
<td class="r3">改良版POIDの中身</td>
|
108
108
|
|
2
誤字
test
CHANGED
File without changes
|
test
CHANGED
@@ -110,11 +110,11 @@
|
|
110
110
|
|
111
111
|
<tr>
|
112
112
|
|
113
|
-
<th class="r1">
|
113
|
+
<th class="r1">ID</th>
|
114
|
-
|
114
|
+
|
115
|
-
<td class="r2">現行版
|
115
|
+
<td class="r2">現行版IDの中身</td>
|
116
|
-
|
116
|
+
|
117
|
-
<td class="r3">改良版
|
117
|
+
<td class="r3">改良版IDの中身</td>
|
118
118
|
|
119
119
|
</tr>
|
120
120
|
|
@@ -216,7 +216,7 @@
|
|
216
216
|
|
217
217
|
PKID: PKID,
|
218
218
|
|
219
|
-
|
219
|
+
id: v_str_id,
|
220
220
|
|
221
221
|
|
222
222
|
|
1
参考のサイトを追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -30,6 +30,12 @@
|
|
30
30
|
|
31
31
|
|
32
32
|
|
33
|
+
foreachで表示させる参考URL
|
34
|
+
|
35
|
+
http://qiita.com/ryo2132/items/63ced19601b3fa30e6de
|
36
|
+
|
37
|
+
|
38
|
+
|
33
39
|
```lang-php
|
34
40
|
|
35
41
|
<!DOCTYPE html>
|