简体   繁体   English

更新列值laravel

[英]Update column value laravel

I'm trying to update a column value to approve a service ( changing the value from 0 to 1 ) and I'm getting an error : 我正在尝试更新列值以批准服务(将值从0更改为1),但出现错误:

Symfony \\ Component \\ HttpKernel \\ Exception \\ MethodNotAllowedHttpException No message Symfony \\组件\\ HttpKernel \\异常\\ MethodNotAllowedHttpException没有消息

This is the Controller : 这是控制器:

<?php

    namespace App\Http\Controllers;

    use Illuminate\Http\Request;
    use Illuminate\Support\Facades\Auth;
    use Illuminate\Support\Facades\Storage;
    use Session;
    use App\Service;

    class ServiceController extends Controller{

      public function approuver($id){

          Service::where([
             'id' => $id,
          ])->update(array('flag'=>1));

          $request->session()->flash('notif','Mise à jour reussi!');

          return back();
     }
 }

This is the route: 这是路线:

 Route::post('/Services/approuver/{id}', 'ServiceController@approuver');

This is the blade file : 这是刀片文件:

<div id="modal1{{$service->id}}" class="modal">
<div class="modal-content">

<p>Voulez vous vraiment approuver ce service ?</p>

 <div class="row">                                
  <form class="col s12"   method="post" 
  action="/Services/approuver/{{$service->id}}">
    {{ csrf_field() }}
      @method('PUT')


       <span>   <input type="submit" class="btn purple hoverable waves 
      effect" value="Oui"></span>
     <span>    <a href="#" class="btn red hoverable waves effect modal- 
     action modal-close" id="Non"> Non</a></span>



   </form> 
   </div>                     

</div>

您正在发出PUT请求,但在您的路由中使用了POST方法在您的路由中做到了这一点

Route::put('/Services/approuver/{id}', 'ServiceController@approuver');

Your route is defined as POST but your form has @method('PUT') . 您的路线定义为POST但您的表单具有@method('PUT') You have to decide which one you want to use. 您必须决定要使用哪一个。

您应该删除@method('PUT')或更改这样定义的路由。

Route::put('/Services/approuver/{id}', 'ServiceController@approuver');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM