此路由不支持 PUT 方法。支持的方法:POST 使用 laravel ajax
The PUT method is not supported for this route. Supported methods: POST using laravel ajax
我有一个公告 table 多张图片,我想更新多张图片,我只想将数据发送到控制器,但它给我错误:The PUT method is not supported for this route. Supported methods: POST
。我不知道不知道哪里出错了
web.php
Route::post('filesUpdate','AnnoncesController@filesUpdate')->name('filesUpdate');
AnnoncesController.php
public function filesUpdate(Request $request)
{
dd($request->all());
}
details.blade.php
<form method="post" action="{{route('filesUpdate')}}" enctype="multipart/form-data" class="dropzone" id="dropzone">
<input type="hidden" name="_method" value="PUT">
{{ csrf_field() }}
</form>
<script type="text/javascript">
Dropzone.options.dropzone =
{
maxFilesize: 12,
renameFile: function(file) {
var images = [];
$(file).each(function(i){
images[i] = file.name;
console.log(images);
});
$.ajax({
url:"{{ route('filesUpdate') }}" ,
type:'POST',
data:{
images : images,
"_token": "{{ csrf_token() }}"
},
success: function(data, status, xhr){
console.log(data, status, xhr);
},
error: function(xhr, status, msg) {
return console.error(xhr, status, msg)
}})
//return images;
},
acceptedFiles: ".jpeg,.jpg,.png,.gif",
addRemoveLinks: true,
timeout: 50000,
success: function(file, response)
{
console.log(response);
},
error: function(file, response)
{
return false;
}
};
</script>
来自laravel docs:
Route::match(['put', 'post'], '/', function () {
//
});
<input type="hidden" name="_method" value="PUT">
负责方法欺骗 - 意味着它指示 Laravel 使用 PUT 方法来处理请求。
由于您的路线定义为POST
Route::post('filesUpdate','AnnoncesController@filesUpdate')->name('filesUpdate');
尝试从表单中删除 <input type="hidden" name="_method" value="PUT">
以消除错误 - 如果有效,则意味着您的表单未通过 ajax
提交
我有一个公告 table 多张图片,我想更新多张图片,我只想将数据发送到控制器,但它给我错误:The PUT method is not supported for this route. Supported methods: POST
。我不知道不知道哪里出错了
web.php
Route::post('filesUpdate','AnnoncesController@filesUpdate')->name('filesUpdate');
AnnoncesController.php
public function filesUpdate(Request $request)
{
dd($request->all());
}
details.blade.php
<form method="post" action="{{route('filesUpdate')}}" enctype="multipart/form-data" class="dropzone" id="dropzone">
<input type="hidden" name="_method" value="PUT">
{{ csrf_field() }}
</form>
<script type="text/javascript">
Dropzone.options.dropzone =
{
maxFilesize: 12,
renameFile: function(file) {
var images = [];
$(file).each(function(i){
images[i] = file.name;
console.log(images);
});
$.ajax({
url:"{{ route('filesUpdate') }}" ,
type:'POST',
data:{
images : images,
"_token": "{{ csrf_token() }}"
},
success: function(data, status, xhr){
console.log(data, status, xhr);
},
error: function(xhr, status, msg) {
return console.error(xhr, status, msg)
}})
//return images;
},
acceptedFiles: ".jpeg,.jpg,.png,.gif",
addRemoveLinks: true,
timeout: 50000,
success: function(file, response)
{
console.log(response);
},
error: function(file, response)
{
return false;
}
};
</script>
来自laravel docs:
Route::match(['put', 'post'], '/', function () {
//
});
<input type="hidden" name="_method" value="PUT">
负责方法欺骗 - 意味着它指示 Laravel 使用 PUT 方法来处理请求。
由于您的路线定义为POST
Route::post('filesUpdate','AnnoncesController@filesUpdate')->name('filesUpdate');
尝试从表单中删除 <input type="hidden" name="_method" value="PUT">
以消除错误 - 如果有效,则意味着您的表单未通过 ajax