在视野中 <form action="{{route('memberPost', $courses->id)}}" method="POST"> @csrf <button type="submit" class="btn clever-btn mb-30 w-100">Ikut course</button> </form>在控制器中public function detail_courses($slug){ $courses = Course::where('slug', $slug)->first(); return view('single-courses', compact('courses','id_courses'));}public function memberPost(Request $request, $id){ $courses = Course::where('id', $id)->first(); $id_courses = $courses->id; $member = Member::create([ 'user_id' => auth()->user()->id, 'course_id' => $id_courses ]); return redirect()->route('detail_courses'); }在途中 Route::group(['middleware' => ['checkRole']], function () { Route::get('/single-courses/{slug}', 'PagesController@detail_courses')->name('detail_courses'); Route::post('/single-courses/{slug}/{id}', 'PagesController@memberPost')->name('memberPost');});当我尝试上面的代码时,出现了这样的错误 Missing required parameters for [Route: memberPost] [URI: single-courses / {slug} / {id}]。
1 回答
不负相思意
TA贡献1777条经验 获得超10个赞
您名为memberPost的路由有另一个需要传递的参数($slug)
Route::post('/single-courses/{slug}/{id}', 'PagesController@memberPost')->name('memberPost');
在表单操作的路线中,您还需要传递 slug
{{route('memberPost', ['slug' => $courses->slug, 'id' => $courses->id])}}
- 1 回答
- 0 关注
- 72 浏览
添加回答
举报
0/150
提交
取消