回答編集履歴
2
修正
test
CHANGED
@@ -29,3 +29,35 @@
|
|
29
29
|
@endforeach
|
30
30
|
|
31
31
|
```
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
```php
|
36
|
+
|
37
|
+
<?php
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
namespace App;
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
use Illuminate\Database\Eloquent\Model;
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
class Cart extends Model
|
50
|
+
|
51
|
+
{
|
52
|
+
|
53
|
+
public function item()
|
54
|
+
|
55
|
+
{
|
56
|
+
|
57
|
+
return $this->belongsTo(Item::class);
|
58
|
+
|
59
|
+
}
|
60
|
+
|
61
|
+
}
|
62
|
+
|
63
|
+
```
|
1
修正
test
CHANGED
@@ -6,9 +6,9 @@
|
|
6
6
|
|
7
7
|
*/
|
8
8
|
|
9
|
-
$cart = Cart::with('item
|
9
|
+
$carts = Cart::with(['item'])->get();
|
10
10
|
|
11
|
-
return view('x
|
11
|
+
return view('carts.index', compact('carts'));
|
12
12
|
|
13
13
|
```
|
14
14
|
|
@@ -22,6 +22,10 @@
|
|
22
22
|
|
23
23
|
*/
|
24
24
|
|
25
|
+
@foreach ($carts as $cart)
|
26
|
+
|
25
|
-
{{ $cart->item
|
27
|
+
{{ $cart->quantity * $cart->item->price }}
|
28
|
+
|
29
|
+
@endforeach
|
26
30
|
|
27
31
|
```
|