質問編集履歴
3
誤字
test
CHANGED
File without changes
|
test
CHANGED
@@ -112,7 +112,7 @@
|
|
112
112
|
|
113
113
|
|
114
114
|
|
115
|
-
"localhost/products/create"でルーティングしているはずが、function create()ではなく、function show()になってしまう理由がわからず困っています。
|
115
|
+
"localhost/products/create"でルーティングしているはずが、コントローラーで、function create()ではなく、function show()になってしまう理由がわからず困っています。
|
116
116
|
|
117
117
|
|
118
118
|
|
2
質問文の修正
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
URLのパラメータにstringが入ってしまう。(Laravel)
|
test
CHANGED
@@ -2,16 +2,136 @@
|
|
2
2
|
|
3
3
|
商品登録機能などが行えるAPIの実装をしています。
|
4
4
|
|
5
|
-
・
|
5
|
+
・閲覧者は、商品の閲覧のみ行うことができる(userは認証機能を必要としない)
|
6
6
|
|
7
|
-
・
|
7
|
+
・user(管理者)は、商品の登録、編集、削除などを行うことができる
|
8
|
+
|
9
|
+
|
10
|
+
|
11
|
+
web.php
|
12
|
+
|
13
|
+
```PHP
|
14
|
+
|
15
|
+
/*
|
16
|
+
|
17
|
+
|--------------------------------------------------------------------------
|
18
|
+
|
19
|
+
| 1) User 認証不要
|
20
|
+
|
21
|
+
|--------------------------------------------------------------------------
|
22
|
+
|
23
|
+
*/
|
24
|
+
|
25
|
+
//商品一覧表示画面
|
26
|
+
|
27
|
+
Route::get('/products', 'ProductController@index')->name('products.index');
|
28
|
+
|
29
|
+
//商品詳細表示画面
|
30
|
+
|
31
|
+
Route::get('/products/{product}', 'ProductController@show')->name('products.show');
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
/*
|
36
|
+
|
37
|
+
|--------------------------------------------------------------------------
|
38
|
+
|
39
|
+
| 2) User ログイン後
|
40
|
+
|
41
|
+
|--------------------------------------------------------------------------
|
42
|
+
|
43
|
+
*/
|
44
|
+
|
45
|
+
//商品登録画面表示
|
46
|
+
|
47
|
+
Route::get('/products/create', 'ProductController@create')->name('products.create');
|
48
|
+
|
49
|
+
//商品登録
|
50
|
+
|
51
|
+
Route::post('/products', 'ProductController@store')->name('products.store');
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
```
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
ProductController.php
|
62
|
+
|
63
|
+
```PHP
|
64
|
+
|
65
|
+
//商品登録画面表示
|
66
|
+
|
67
|
+
public function create()
|
68
|
+
|
69
|
+
{
|
70
|
+
|
71
|
+
return view('products.create');
|
72
|
+
|
73
|
+
}
|
74
|
+
|
75
|
+
//商品詳細画面
|
76
|
+
|
77
|
+
public function show(Request $request, int $productId)
|
78
|
+
|
79
|
+
{
|
80
|
+
|
81
|
+
dd($productId);
|
82
|
+
|
83
|
+
//idが一致する商品を取得
|
84
|
+
|
85
|
+
$product = Product::find($productId);
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
return view('products.show', [
|
90
|
+
|
91
|
+
'product' => $product,
|
92
|
+
|
93
|
+
]);
|
94
|
+
|
95
|
+
}
|
96
|
+
|
97
|
+
```
|
8
98
|
|
9
99
|
|
10
100
|
|
11
101
|
###困っていること
|
12
102
|
|
13
|
-
|
103
|
+
URLのパラメータにint型以外のものが入力できてしまい、指定されたパラメーターがURLの正しい場所へ埋め込まれない。
|
14
104
|
|
15
|
-
|
105
|
+
具体的には、URLで"localhost/product/create"を指定すると、$productIdがcreateと認識されてしまい、
|
16
106
|
|
107
|
+
> show() must be of the type int, string given
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
というエラーが出てしまう。
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
"localhost/products/create"でルーティングしているはずが、function create()ではなく、function show()になってしまう理由がわからず困っています。
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
###試したこと
|
120
|
+
|
121
|
+
ProductController.php
|
122
|
+
|
123
|
+
```PHP
|
124
|
+
|
125
|
+
public function show(Request $request, int $productId)
|
126
|
+
|
127
|
+
```
|
128
|
+
|
129
|
+
を
|
130
|
+
|
131
|
+
```PHP
|
132
|
+
|
133
|
+
public function show(Request $request, $productId)
|
134
|
+
|
135
|
+
```
|
136
|
+
|
17
|
-
|
137
|
+
とし、$productIdに入っている値を確認したところ、"create"と出ました。
|
1
質問文の修正
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
管理者(admin)の設計
|
1
|
+
管理者(admin)の設計について(Laravel)
|
test
CHANGED
File without changes
|