带有资源的Controller中的自定义功能无法正常工作 [英] Custom function in Controller with resource wont work
问题描述
我在RoomsController中创建了自己的自定义函数
I have created my own custom function in my RoomsController
public function join($id){
return $id;
}
然后我想将变量传递给它,并说MethodNotAllowedHttpException 我的表格看起来像这样
Then I want to pass variable to it and it says MethodNotAllowedHttpException And my Form looks like this
{{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');
我尝试了许多不同的方式,但我不知道为什么它不起作用.所有更新编辑销毁资源功能均正常运行.感谢您的帮助:)
I have tried in many different ways i dont know why it is not working. All update edit destroy resource functions are working. Thank's for helping :)
推荐答案
您正在提交POST
请求,但路由期望出现GET
请求.如果您将路线更改为Route::post('/rooms/join', 'RoomsController@join');
,则该路线应该有效
You're submitting a POST
request but the route is expecting a GET
request. If you change your route to Route::post('/rooms/join', 'RoomsController@join');
it should work
这篇关于带有资源的Controller中的自定义功能无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!