得到错误 POST 方法
getting errors The POST method
我的编辑页面有问题。提交时出现此错误:
Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException
The GET method is not supported for this route. Supported methods:
POST
.
我不知道它是从哪里来的,因为我是 Laravel 的新手。
web.php
Route::post('/admin/add_reseller','ResellerController@addReseller');
Controller.php
public function addReseller(){
return view ('admin.resellers.add_reseller');
}
add_reseller.blade.php
<form class="form-horizontal" method="post" action="" name="addreseller" id="addreseller">
{{ csrf_field() }}
<form class="form-horizontal" method="post" action="" name="addreseller" id="addreseller">
你的action在form
里面是空的,需要在里面添加相应的路由
我建议您使用命名路由。
https://laravel.com/docs/7.x/routing#named-routes
在web.php
Route::post('/admin/add_reseller','ResellerController@addReseller')->name('admin.add.reseller');
然后在你的 blade 文件中,你可以使用 route()
函数引用路由,方法是将路由名称作为参数传递
<form class="form-horizontal" method="post" action="{{route('admin.add.reseller')}}" name="addreseller" id="addreseller">
提示:
首先,我会使用命名路由,这意味着您将 ->name('someName')
添加到您的路由中。这使得路线的使用更加容易,如果您认为 url 不适合您,则无需在您使用路线的任何地方更改它。
https://laravel.com/docs/7.x/routing#named-routes
e.g. Route::post('/admin/add_reseller',
'ResellerController@addReseller')->name('admin.reseller');
问题:
我看到的是,您的 <form>
中缺少 action
属性的值。需要执行此操作,以便在提交表单时选择正确的路径。
解法:
我猜你只需要为属性添加 action="{{route('admin.reseller')}}"
,这样请求就会走正确的路线。
我的编辑页面有问题。提交时出现此错误:
Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException
The GET method is not supported for this route. Supported methods: POST
.
我不知道它是从哪里来的,因为我是 Laravel 的新手。
web.php
Route::post('/admin/add_reseller','ResellerController@addReseller');
Controller.php
public function addReseller(){
return view ('admin.resellers.add_reseller');
}
add_reseller.blade.php
<form class="form-horizontal" method="post" action="" name="addreseller" id="addreseller">
{{ csrf_field() }}
<form class="form-horizontal" method="post" action="" name="addreseller" id="addreseller">
你的action在form
里面是空的,需要在里面添加相应的路由
我建议您使用命名路由。 https://laravel.com/docs/7.x/routing#named-routes
在web.php
Route::post('/admin/add_reseller','ResellerController@addReseller')->name('admin.add.reseller');
然后在你的 blade 文件中,你可以使用 route()
函数引用路由,方法是将路由名称作为参数传递
<form class="form-horizontal" method="post" action="{{route('admin.add.reseller')}}" name="addreseller" id="addreseller">
提示:
首先,我会使用命名路由,这意味着您将 ->name('someName')
添加到您的路由中。这使得路线的使用更加容易,如果您认为 url 不适合您,则无需在您使用路线的任何地方更改它。
https://laravel.com/docs/7.x/routing#named-routes
e.g. Route::post('/admin/add_reseller',
'ResellerController@addReseller')->name('admin.reseller');
问题:
我看到的是,您的 <form>
中缺少 action
属性的值。需要执行此操作,以便在提交表单时选择正确的路径。
解法:
我猜你只需要为属性添加 action="{{route('admin.reseller')}}"
,这样请求就会走正确的路线。