質問編集履歴
4
文の追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -26,8 +26,6 @@
|
|
26
26
|
|
27
27
|
|
28
28
|
|
29
|
-
|
30
|
-
|
31
29
|
下記のコードはマイページの注文一覧をしようとしたコードです
|
32
30
|
|
33
31
|
アドバイスをもとにいろいろやってよくわからない形になり、いきず待ってしまったのでアドバイスいただけると幸いです。
|
3
文の追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -30,6 +30,8 @@
|
|
30
30
|
|
31
31
|
下記のコードはマイページの注文一覧をしようとしたコードです
|
32
32
|
|
33
|
+
アドバイスをもとにいろいろやってよくわからない形になり、いきず待ってしまったのでアドバイスいただけると幸いです。
|
34
|
+
|
33
35
|
現状お店に対して、ほかの注文した商品も入っているところです。
|
34
36
|
|
35
37
|
UserController
|
@@ -84,29 +86,27 @@
|
|
84
86
|
|
85
87
|
{
|
86
88
|
|
87
|
-
$reservations =
|
89
|
+
$reservations = DB::table('reservations')->where('user_id', $id)->latest()->get();
|
88
|
-
|
89
|
-
$shops_id = $reservations->pluck('shop_id');
|
90
|
-
|
91
|
-
$cc = $reservations->pluck('created_at');
|
92
|
-
|
93
|
-
$shop_id = $cc->unique();
|
94
90
|
|
95
91
|
$res_shops = array();
|
96
92
|
|
93
|
+
foreach ($reservations->groupBy('shop_id.created_at') as $re) {
|
94
|
+
|
95
|
+
$shop_id = $re->pluck('shop_id');
|
96
|
+
|
97
|
-
foreach ($shop_id as $sh_id) {
|
97
|
+
foreach ($shop_id as $sh_id) {
|
98
|
-
|
98
|
+
|
99
|
-
$shop = Shop::where('id', $sh_id)->get();
|
99
|
+
$shop = Shop::where('id', $sh_id)->get();
|
100
|
+
|
100
|
-
|
101
|
+
}
|
101
|
-
|
102
|
-
|
102
|
+
|
103
|
-
array_push($res_shops,$shop);
|
103
|
+
array_push($res_shops, $shop);
|
104
104
|
|
105
105
|
}
|
106
106
|
|
107
107
|
$commodities = array();
|
108
108
|
|
109
|
-
$commodity_id = $re
|
109
|
+
$commodity_id = $re->pluck('commodity_id');
|
110
110
|
|
111
111
|
foreach ($commodity_id as $com_id) {
|
112
112
|
|
2
文の追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -20,6 +20,8 @@
|
|
20
20
|
|
21
21
|
migrate関連DB関連載せておきました。
|
22
22
|
|
23
|
+
image(写真)は載せないことにしたので無視してください。
|
24
|
+
|
23
25
|
よろしくお願いします。
|
24
26
|
|
25
27
|
|
1
文の追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -16,7 +16,11 @@
|
|
16
16
|
|
17
17
|
|
18
18
|
|
19
|
-
|
19
|
+
返信遅くなってしまいすみません。
|
20
|
+
|
21
|
+
migrate関連DB関連載せておきました。
|
22
|
+
|
23
|
+
よろしくお願いします。
|
20
24
|
|
21
25
|
|
22
26
|
|
@@ -117,3 +121,345 @@
|
|
117
121
|
}
|
118
122
|
|
119
123
|
```
|
124
|
+
|
125
|
+
**User.php**
|
126
|
+
|
127
|
+
```
|
128
|
+
|
129
|
+
<?php
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
namespace App;
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
use Illuminate\Contracts\Auth\MustVerifyEmail;
|
138
|
+
|
139
|
+
use Illuminate\Foundation\Auth\User as Authenticatable;
|
140
|
+
|
141
|
+
use Illuminate\Notifications\Notifiable;
|
142
|
+
|
143
|
+
|
144
|
+
|
145
|
+
class User extends Authenticatable
|
146
|
+
|
147
|
+
{
|
148
|
+
|
149
|
+
use Notifiable;
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
/**
|
154
|
+
|
155
|
+
* The attributes that are mass assignable.
|
156
|
+
|
157
|
+
*
|
158
|
+
|
159
|
+
* @var array
|
160
|
+
|
161
|
+
*/
|
162
|
+
|
163
|
+
protected $fillable = [
|
164
|
+
|
165
|
+
'name', 'email', 'password',
|
166
|
+
|
167
|
+
];
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
/**
|
172
|
+
|
173
|
+
* The attributes that should be hidden for arrays.
|
174
|
+
|
175
|
+
*
|
176
|
+
|
177
|
+
* @var array
|
178
|
+
|
179
|
+
*/
|
180
|
+
|
181
|
+
protected $hidden = [
|
182
|
+
|
183
|
+
'password', 'remember_token',
|
184
|
+
|
185
|
+
];
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
/**
|
190
|
+
|
191
|
+
* The attributes that should be cast to native types.
|
192
|
+
|
193
|
+
*
|
194
|
+
|
195
|
+
* @var array
|
196
|
+
|
197
|
+
*/
|
198
|
+
|
199
|
+
protected $casts = [
|
200
|
+
|
201
|
+
'email_verified_at' => 'datetime',
|
202
|
+
|
203
|
+
];
|
204
|
+
|
205
|
+
|
206
|
+
|
207
|
+
public function shops()
|
208
|
+
|
209
|
+
{
|
210
|
+
|
211
|
+
return $this->hasMany('App\Shop', 'favorites', 'user_id', 'shop_id')->withTimestamps();
|
212
|
+
|
213
|
+
}
|
214
|
+
|
215
|
+
|
216
|
+
|
217
|
+
|
218
|
+
|
219
|
+
public function reservation()
|
220
|
+
|
221
|
+
{
|
222
|
+
|
223
|
+
return $this->belongsTo('App\Reservation');
|
224
|
+
|
225
|
+
}
|
226
|
+
|
227
|
+
|
228
|
+
|
229
|
+
}
|
230
|
+
|
231
|
+
```
|
232
|
+
|
233
|
+
**Shop.php**
|
234
|
+
|
235
|
+
```ここに言語を入力
|
236
|
+
|
237
|
+
<?php
|
238
|
+
|
239
|
+
|
240
|
+
|
241
|
+
namespace App;
|
242
|
+
|
243
|
+
|
244
|
+
|
245
|
+
use Illuminate\Database\Eloquent\Model;
|
246
|
+
|
247
|
+
|
248
|
+
|
249
|
+
class Shop extends Model
|
250
|
+
|
251
|
+
{
|
252
|
+
|
253
|
+
protected $fillable = [
|
254
|
+
|
255
|
+
'sname',
|
256
|
+
|
257
|
+
'region',
|
258
|
+
|
259
|
+
'sprice',
|
260
|
+
|
261
|
+
'detail',
|
262
|
+
|
263
|
+
'store_in',
|
264
|
+
|
265
|
+
'take_out',
|
266
|
+
|
267
|
+
'delivery',
|
268
|
+
|
269
|
+
];
|
270
|
+
|
271
|
+
|
272
|
+
|
273
|
+
public function commodities()
|
274
|
+
|
275
|
+
{
|
276
|
+
|
277
|
+
return $this->hasMany('App\Commodity');
|
278
|
+
|
279
|
+
}
|
280
|
+
|
281
|
+
|
282
|
+
|
283
|
+
public function images()
|
284
|
+
|
285
|
+
{
|
286
|
+
|
287
|
+
return $this->hasMany('App\Image');
|
288
|
+
|
289
|
+
}
|
290
|
+
|
291
|
+
|
292
|
+
|
293
|
+
public function users()
|
294
|
+
|
295
|
+
{
|
296
|
+
|
297
|
+
return $this->belongsToMany('App\User', 'favorites', 'shop_id', 'user_id');
|
298
|
+
|
299
|
+
}
|
300
|
+
|
301
|
+
|
302
|
+
|
303
|
+
|
304
|
+
|
305
|
+
public function reservation()
|
306
|
+
|
307
|
+
{
|
308
|
+
|
309
|
+
return $this->belongsTo('App\Reservation');
|
310
|
+
|
311
|
+
}
|
312
|
+
|
313
|
+
}
|
314
|
+
|
315
|
+
```
|
316
|
+
|
317
|
+
**Commodity.php**
|
318
|
+
|
319
|
+
```ここに言語を入力
|
320
|
+
|
321
|
+
<?php
|
322
|
+
|
323
|
+
|
324
|
+
|
325
|
+
namespace App;
|
326
|
+
|
327
|
+
|
328
|
+
|
329
|
+
use Illuminate\Database\Eloquent\Model;
|
330
|
+
|
331
|
+
|
332
|
+
|
333
|
+
class Commodity extends Model
|
334
|
+
|
335
|
+
{
|
336
|
+
|
337
|
+
|
338
|
+
|
339
|
+
protected $fillable = [
|
340
|
+
|
341
|
+
'name',
|
342
|
+
|
343
|
+
'price',
|
344
|
+
|
345
|
+
'description',
|
346
|
+
|
347
|
+
];
|
348
|
+
|
349
|
+
|
350
|
+
|
351
|
+
public function images()
|
352
|
+
|
353
|
+
{
|
354
|
+
|
355
|
+
return $this->hasMany('App\Image');
|
356
|
+
|
357
|
+
}
|
358
|
+
|
359
|
+
|
360
|
+
|
361
|
+
public function reservations()
|
362
|
+
|
363
|
+
{
|
364
|
+
|
365
|
+
return $this->hasMany('App\Reservation');
|
366
|
+
|
367
|
+
}
|
368
|
+
|
369
|
+
|
370
|
+
|
371
|
+
public function user()
|
372
|
+
|
373
|
+
{
|
374
|
+
|
375
|
+
return $this->belongsTo('App\User');
|
376
|
+
|
377
|
+
}
|
378
|
+
|
379
|
+
|
380
|
+
|
381
|
+
public function shop()
|
382
|
+
|
383
|
+
{
|
384
|
+
|
385
|
+
return $this->belongsTo('App\Shop');
|
386
|
+
|
387
|
+
}
|
388
|
+
|
389
|
+
}
|
390
|
+
|
391
|
+
```
|
392
|
+
|
393
|
+
**Reservation.php**
|
394
|
+
|
395
|
+
```ここに言語を入力
|
396
|
+
|
397
|
+
<?php
|
398
|
+
|
399
|
+
|
400
|
+
|
401
|
+
namespace App;
|
402
|
+
|
403
|
+
|
404
|
+
|
405
|
+
use Illuminate\Database\Eloquent\Model;
|
406
|
+
|
407
|
+
|
408
|
+
|
409
|
+
class Reservation extends Model
|
410
|
+
|
411
|
+
{
|
412
|
+
|
413
|
+
protected $fillable = [
|
414
|
+
|
415
|
+
'remark',
|
416
|
+
|
417
|
+
];
|
418
|
+
|
419
|
+
|
420
|
+
|
421
|
+
public function images()
|
422
|
+
|
423
|
+
{
|
424
|
+
|
425
|
+
return $this->hasMany('App\Image');
|
426
|
+
|
427
|
+
}
|
428
|
+
|
429
|
+
|
430
|
+
|
431
|
+
public function shops()
|
432
|
+
|
433
|
+
{
|
434
|
+
|
435
|
+
return $this->hasMany('App\Shop');
|
436
|
+
|
437
|
+
}
|
438
|
+
|
439
|
+
|
440
|
+
|
441
|
+
public function user()
|
442
|
+
|
443
|
+
{
|
444
|
+
|
445
|
+
return $this->belongsTo('App\User');
|
446
|
+
|
447
|
+
}
|
448
|
+
|
449
|
+
|
450
|
+
|
451
|
+
public function commodity()
|
452
|
+
|
453
|
+
{
|
454
|
+
|
455
|
+
return $this->belongdTo('App\Commodity');
|
456
|
+
|
457
|
+
}
|
458
|
+
|
459
|
+
}
|
460
|
+
|
461
|
+
```
|
462
|
+
|
463
|
+
**DB Reservationテーブル**
|
464
|
+
|
465
|
+
![](3ccafb6abf04a78ffe44359debc9f65e.jpeg)
|