質問編集履歴

2

web.phpとコントローラーのコードを記載しました

2021/03/19 12:04

投稿

wcymn
wcymn

スコア8

test CHANGED
File without changes
test CHANGED
@@ -133,3 +133,89 @@
133
133
 
134
134
 
135
135
  お力添えいただけますと幸いです。
136
+
137
+
138
+
139
+ ### ドキュメントルート
140
+
141
+
142
+
143
+ web.php
144
+
145
+ ```php
146
+
147
+ Route::GET('/thread', 'App\Http\Controllers\ThreadController@index');
148
+
149
+ Route::GET('/thread/id={id}', 'App\Http\Controllers\PostController@index');
150
+
151
+ Route::POST('/thread/new_post', 'App\Http\Controllers\PostController@store')->middleware('auth');;
152
+
153
+
154
+
155
+ ```
156
+
157
+
158
+
159
+ ### PostController
160
+
161
+
162
+
163
+ App/Http/Controllers/PostController.php
164
+
165
+ ```php
166
+
167
+ <?php
168
+
169
+
170
+
171
+ namespace App\Http\Controllers;
172
+
173
+
174
+
175
+ use App\Models\thread;
176
+
177
+ use App\Models\Post;
178
+
179
+ use Illuminate\Http\Request;
180
+
181
+
182
+
183
+ class PostController extends Controller
184
+
185
+ {
186
+
187
+ /**
188
+
189
+ * Display a listing of the resource.
190
+
191
+ *
192
+
193
+ * @return \Illuminate\Http\Response
194
+
195
+ */
196
+
197
+ public function index(Request $request)
198
+
199
+ {
200
+
201
+ $thread_no = $request->id;
202
+
203
+ $thread = Thread::findOrFail($thread_no);
204
+
205
+ $posts = Post::where("thread_no", $thread_no)->get();
206
+
207
+ return view('thread')->with([
208
+
209
+ 'thread' => $thread,
210
+
211
+ 'posts' => $posts,
212
+
213
+ ]);
214
+
215
+ }
216
+
217
+ //略
218
+
219
+ }
220
+
221
+ ```

1

初心者アイコンをオンにさせていただきました

2021/03/19 12:04

投稿

wcymn
wcymn

スコア8

test CHANGED
File without changes
test CHANGED
@@ -128,7 +128,7 @@
128
128
 
129
129
 
130
130
 
131
- 原因がコントローラーなのかbladeなのかの判別もできず、調べてみたものの似た事例を見つけることができなかったためこちらに質問させていただきました。
131
+ 原因がコントローラーなのかbladeなのかの判別もできず、ネットで調べてみたものの似た事例を見つけることができなかったためこちらに質問させていただきました。
132
132
 
133
133
 
134
134