teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

2

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

2021/03/19 12:04

投稿

wcymn
wcymn

スコア8

title CHANGED
File without changes
body CHANGED
@@ -65,4 +65,47 @@
65
65
 
66
66
  原因がコントローラーなのかbladeなのかの判別もできず、ネットで調べてみたものの似た事例を見つけることができなかったためこちらに質問させていただきました。
67
67
 
68
- お力添えいただけますと幸いです。
68
+ お力添えいただけますと幸いです。
69
+
70
+ ### ドキュメントルート
71
+
72
+ web.php
73
+ ```php
74
+ Route::GET('/thread', 'App\Http\Controllers\ThreadController@index');
75
+ Route::GET('/thread/id={id}', 'App\Http\Controllers\PostController@index');
76
+ Route::POST('/thread/new_post', 'App\Http\Controllers\PostController@store')->middleware('auth');;
77
+
78
+ ```
79
+
80
+ ### PostController
81
+
82
+ App/Http/Controllers/PostController.php
83
+ ```php
84
+ <?php
85
+
86
+ namespace App\Http\Controllers;
87
+
88
+ use App\Models\thread;
89
+ use App\Models\Post;
90
+ use Illuminate\Http\Request;
91
+
92
+ class PostController extends Controller
93
+ {
94
+ /**
95
+ * Display a listing of the resource.
96
+ *
97
+ * @return \Illuminate\Http\Response
98
+ */
99
+ public function index(Request $request)
100
+ {
101
+ $thread_no = $request->id;
102
+ $thread = Thread::findOrFail($thread_no);
103
+ $posts = Post::where("thread_no", $thread_no)->get();
104
+ return view('thread')->with([
105
+ 'thread' => $thread,
106
+ 'posts' => $posts,
107
+ ]);
108
+ }
109
+ //略
110
+ }
111
+ ```

1

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

2021/03/19 12:04

投稿

wcymn
wcymn

スコア8

title CHANGED
File without changes
body CHANGED
@@ -63,6 +63,6 @@
63
63
 
64
64
  example.com/thread/id=1を叩いた際にどんな条件でもAuth::user()->idが想定通りログインしているアカウントのものが表示できるようにしたく存じています。
65
65
 
66
- 原因がコントローラーなのかbladeなのかの判別もできず、調べてみたものの似た事例を見つけることができなかったためこちらに質問させていただきました。
66
+ 原因がコントローラーなのかbladeなのかの判別もできず、ネットで調べてみたものの似た事例を見つけることができなかったためこちらに質問させていただきました。
67
67
 
68
68
  お力添えいただけますと幸いです。