【问题标题】:Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException The PUT method is not supported for this route. Supported methods: GET, HEADSymfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException 此路由不支持 PUT 方法。支持的方法:GET、HEAD
【发布时间】:2020-08-10 17:06:31
【问题描述】:

'我无法更新数据错误此路由不支持 PUT 方法。支持的方法:GET、HEAD。我不知道我需要帮助谢谢' '这是我的控制器'

  public function edit($id){

        $slider = DB::table('header_sliders')->find($id);

        return   view('posts.edit',['header'=>$slider]);

       }

       public function update(Request $request,$id){

        $slider = DB::table('header_sliders')->find($id);

        $header->text = $request->input('text');
        $header->imgName = $request->input('imgName');

        $header->update();

        return  redirect('admin/index',['header'=>$slider]);

       }

'这是我的看法'

 <div class="container">
    <div class="row">
    <div class="col-md-12">
    <form action="{{url('admin/edit/'.$header->id)}}"  method="POST" >
    {{csrf_field()}}
    {{method_field('PUT')}}

    <div class="form-group">
        <label for="exampleInputEmail1">Mətn</label>
        <input type="text" name="text" class="form-control"  aria-describedby="emailHelp" value="{{$header->text}}">
        <small id="emailHelp" class="form-text text-muted"></small>
    </div>
    <div class="form-group">
        <label for="exampleInputPassword1">Şəkil</label>
        <input type="file" name="imgName" class="form-control"  value="{{$header->imgName}}">
    </div>

    <div class="form-check">
    </div>
    <a href ="{{url('admin/index')}}"><button type="submit" class="btn btn-primary">Dəyiş</button></a>

    </form>
    </div>
    </div>
    </div>

【问题讨论】:

  • 你能分享你的路线web.php文件吗?
  • 是 Route::put('admin/index, Admin\HeaderSlidercontroller@update');
  • 你缺少引号,你需要Route::put('admin/index', 'Admin\HeaderSlidercontroller@update');

标签: php laravel


【解决方案1】:

运行命令帮助了我

php artisan optimize:clear

谢谢

【讨论】:

    【解决方案2】:

    你的路由admin/edit/只接受GET,你应该把它改成:

    Route::put('admin/edit/{header}', 'Admin\HeaderSlidercontroller@update');
    

    并删除a标签:

    <a href ="{{url('admin/index')}}">
    

    【讨论】:

    • 我正在改变,从空值创建默认对象 $header->text = $request->input('text');
    • 你没有在你的控制器中声明$header,你的意思是$slider吗?
    • okey 代码工作但有一个问题)调用未定义的方法 stdClass::update()
    • 用控制器代码中的滑块替换所有标题
    • 请删除a标签,如更新的答案所示
    【解决方案3】:

    最好检查路线是否存在,如果不存在,则应该创建它

    php artisan route:list

    根据您的观点,路线存在冲突

     <form action="{{url('admin/edit/'.$header->id)}}"  method="POST" >
     {{method_field('PUT')}}`
    

    确保您需要做什么,PUTPOST 但不能同时进行

    这条路由Route::put('admin/index, Admin\HeaderSlidercontroller@update');没有参数,所以不需要给html表单添加参数

    &lt;form action="{{url('admin/index')}}" method="PUT" &gt;

    并删除此a 标签 &lt;a href ="{{url('admin/index')}}"&gt; ...

    【讨论】:

      【解决方案4】:

      据我了解,您尝试在无效的 get 方法路径上提交表单:

      您需要按照以下方式更改表单中的路线:

      <form action="{{url('admin/update/'.$header->id)}}"  method="POST">
      

      【讨论】:

        猜你喜欢
        • 2020-02-04
        • 2020-02-08
        • 2021-02-24
        • 1970-01-01
        • 1970-01-01
        • 2019-12-29
        • 2020-04-03
        • 2020-05-27
        • 1970-01-01
        相关资源
        最近更新 更多