Laravel表单提交在RouteCollection.php第218行显示MethodNotAllowedHttpException:
问题描述:
This is my route
Route::resource('admin/reports', 'ReportController');
This is controller function
public function store(Request $request)
{
return "Thank you";
}
This is my html code
{!! Form::open([ 'url' => 'admin/reports/store', 'files' => true, 'enctype' => 'multipart/form-data', 'class' => 'dropzone', 'id' => 'reportfile' ]) !!}
{!! csrf_field() !!}
<div class="col-md-12">
<h3 style="text-align : center">Select File</h3>
</div>
<div class="col-md-12" style="text-align: center; padding: 10px">
<button type="submit" class="btn btn-primary">Upload Report</button>
</div>
{!! Form::close() !!}
When I submit the form, it show me MethodNotAllowedHttpException in RouteCollection.php line 218:
Any help is much appreciated. Thanks
这是我的路线 p>
Route :: resource(' admin / reports','ReportController');
code> pre>
这是控制器功能 p>
公共功能存储(请求 $ request)
{
返回“谢谢”;
}
code> pre>
这是我的html代码 p>
{!! Form :: open(['url'=&gt;'admin / reports / store','files'=&gt; true,'enctype'=&gt;'multipart / form-data','class'=&gt;'dropzone ','id'=&gt;'reportfile'])!!}
{!! csrf_field()!!}
&lt; div class =“col-md-12”&gt;
&lt; h3 style =“text-align:center”&gt;选择文件&lt; / h3&gt;
&lt; / div&gt ;
&lt; div class =“col-md-12”style =“text-align:center; padding:10px”&gt;
&lt; button type =“submit”class =“btn btn-primary” &gt;上传报告&lt; / button&gt;
&lt; / div&gt;
{!! Form :: close()!!}
code> pre>
当我提交表单时,它会在RouteCollection.php第218行显示MethodNotAllowedHttpException: p>
\ n
非常感谢任何帮助。 谢谢 p>
div>
答
Your form action should just be admin/reports.
Currently it will assume you are trying to post to the route admin/reports/{id}. That endpoint is used with GET, PUT and DELETE.
Check the docs including a table giving you routes https://laravel.com/docs/5.1/controllers#restful-resource-controllers if I were you I'd use the route helper to generate your urls for you