Laravel 此路由不支持POST方法。支持的方法:GET,HEAD。在拉维尔

Laravel 此路由不支持POST方法。支持的方法:GET,HEAD。在拉维尔,laravel,Laravel,我想为包选择一些文件,但我有一个错误 SingleproductController: public function syncFiles(Request $request , $id){ $files = product_file::all(); $product_item = Singleproduct::find($id); $product_files = $product_item->file()->get()->pluck('

我想为包选择一些文件,但我有一个错误

SingleproductController:

 public  function syncFiles(Request $request , $id){
      $files = product_file::all();
      $product_item = Singleproduct::find($id);
      $product_files = $product_item->file()->get()->pluck('id')->toArray();
        return view('admin.SingleProduct.productSync'  , compact('files' , 'product_files'));
   }
刀片:

  @if( $files && count($files) > 0)
        <form action="{{ route('product.updatesync_files')}}" method="post">
            {{ csrf_field()  }}
            <h3 style="color: black; ">فایل مربوطه:</h3>
            <section class="panel">
                <table class="table table-striped table-advance table-hover">
            <ul>
                @foreach($files as $file)
                    <li>
                        <input type="checkbox" name="files[]" value="{{ $file->file_id  }}" {{ isset($id) && in_array($file->id,$id) ? 'checked':''  }}>
                        {{ $file->file_name }}
                    </li>
                @endforeach
            </ul>
            <div class="form-group">
                <input type="submit" class="btn btn-danger" name="submit_product_files" value="ذخیره اطلاعات">
            </div>
                </table>
            </section>
        </form>
    @endif

错误是:“此路由不支持POST方法。支持的方法:GET,HEAD。”

如果您尚未在表单上指定操作(或指定的操作为空),ot将在表单所在的同一url上重定向, 在这种情况下,解决方案是为表单指定正确的操作

如我所见,您有以下名为
product.updatesync\u文件的路由:

Route::post('/product/updatesync_files/{id}', 'SingleproductController@updateSyncFiles')->name('product.updatesync_files');
您可以将此路由添加到表单中:

<form action="{{ route('product.updatesync_files') }}" method="post">

如果在表单中上载文件,则缺少enctype=“multipart/form data”属性,这对于上载文件很重要

这是您的申请表

<form action="{{ route('product.updatesync_files')}}" method="post" enctype="multipart/form-data">

欲了解更多信息,请阅读此


您的表单没有操作?当前表单中没有操作。这是哪个刀片文件@如果($files&&count($files)>0)我编辑了它,现在我有了新的错误:“缺少[Route:product.updatesync_files][URI]所需的参数,我真的不知道应该传递哪个参数!!我这样做了,现在我有了新的错误:“未定义的变量:id”您实际上没有变量id,您必须知道它是什么参数,并将该变量放在其中,如图所示:Route::post('/product/updatesync_files/{id}','SingleproductController@updateSyncFiles')->name('product.updatesync_文件');它是id!我不想取消重新启动,我应该用什么来代替我在“updatesyncFiles”方法中使用它。
$product\u item=Singleproduct::find($id);
,这就是
Singleproduct
id
<form action="{{ route('product.updatesync_files') }}" method="post">
<form action="{{ route('product.updatesync_files', ['id' => $id]) }}" method="post">
<form action="{{ route('product.updatesync_files')}}" method="post" enctype="multipart/form-data">