我在RoomsController中创建了自己的自定义函数
public function join($id){
return $id;
}
然后我想将变量传递给它,它说MethodNotAllowedHttpException 我的表格看起来像这样
{{Form::open(['action'=> ['RoomsController@join', $room->id], 'method' => 'POST' ])}}
{{Form::submit('Join', ['class' => 'btn btn-danger'])}}
{{Form::close()}}
Also have these routes
Route::get('/','PagesController@index');
Route::get('/about', 'PagesController@about');
Route::get('/services', 'PagesController@services');
Route::get('/register', 'PagesController@register');
Route::get('/logout', 'PagesController@logout');
Route::get('/rooms/join', 'RoomsController@join');
Route::resource('posts','PostsController');
Route::resource('rooms','RoomsController');
Auth::routes();
Route::get('/dashboard', 'DashboardController@index');
我尝试过许多不同的方式,我不知道为什么它不起作用。所有更新编辑销毁资源功能正在运行。感谢您的帮助:))
答案 0 :(得分:0)
您正在提交POST
请求,但路由期待GET
请求。如果您将路线更改为Route::post('/rooms/join', 'RoomsController@join');
,则应该有效
答案 1 :(得分:0)
将方法更改为发布并将路径放在资源路径下面
Route::resource('rooms','RoomsController');
Route::post('/rooms/join', 'RoomsController@join');