我得到" MethodNotAllowedHttpException"表单提交错误,但我无法弄清楚原因。这是我的表格,由Laravel Collective表单创建者创建:
{!! Form::open(['url' => 'photographer/listing/store', 'method'=>'POST', 'files' => true]) !!}
//Bunch of Form Inputs here:
{!!Form::submit('Create Listing')!!}
{!! Form::close() !!}
然后这是我的路线:
Route::post('photographer/listing/store', 'PhotographerController@storeListing');
最后,这是控制器:
class PhotographerController extends Controller
{
public function storeListing(Request $request)
{
//Form Validation
//Store in the database
return redirect('/photographer');
}
}
从我所看到的,当您对请求使用不正确的方法时会出现此错误,例如。路线是一个形式是帖子的获取,但这不是这里的情况,所以我不知道发生了什么。
更新:我还在此处提供php artisan route:list
的相关信息:
POST | photographer/listing/store | | App\Http\Controllers\PhotographerController@storeListing | web,auth:photographer
GET|HEAD | photographer | photographer.dashboard | App\Http\Controllers\PhotographerController@index | web,auth:photographer
答案 0 :(得分:0)
您是否检查过表单操作上的网址是否正确?
我的猜测是以下一行:
{!! Form::open(['url' => 'photographer/listing/store', 'method'=>'POST', 'files' => true]) !!}
没有指向您期望的相对网址。尝试在url参数中添加正斜杠,如下所示:
{!! Form::open(['url' => '/photographer/listing/store', 'method'=>'POST', 'files' => true]) !!}