在视野中
<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}]。
不负相思意