laravel vue将阵列发送到后端

laravel vue将阵列发送到后端,laravel,Laravel,我想用vuejs表中的一个按钮将id的数组发送到后端,但得到错误500 逻辑 选中复选框 收集身份证 单击按钮时将id发送到后端 更新视图 代码 模板 <table class="table table-dark table-hover table-bordered table-striped"> <thead> <tr> <th class="text-center" width="50"> //the button

我想用vuejs表中的一个按钮将
id的数组
发送到后端,但得到错误500

逻辑
  • 选中复选框
  • 收集身份证
  • 单击按钮时将id发送到后端
  • 更新视图
  • 代码
    模板

    <table class="table table-dark table-hover table-bordered table-striped">
      <thead>
        <tr>
          <th class="text-center" width="50">
    //the button
            <button class="btn btn-outline-danger" @click="withdraw(index)">Withdraw</button>
          </th>
          <th class="text-center" width="50">#</th>
          <th class="text-center">Amount</th>
        </tr>
      </thead>
      <tbody>
        <tr v-for="(income,index) in incomes" v-bind:key="index">
        <td class="text-center">
     //check box input
          <input v-if="income.withdraw == '0'" type="checkbox" :id="income.id" :value="income.amount" v-model="checkedNumbers">
        </td>
        <td class="text-center">{{index+1}}</td>
        <td class="text-center">Rp. {{formatPrice(income.amount)}}</td>
       </tr>
       <tr>
        <td colspan="2"></td>
        <td>
          <span>Withdraw for today, Sum: <br> Rp. {{ formatPrice(sum) }}</span>
        </td>
       </tr>
      </tbody>
    </table>
    
    路线

    Route::post('withdrawbutton/{id}', 'IncomeController@withdrawbutton');
    
    控制器

    public function withdrawbutton($id)
    {
      $dowithdraw = Income::where('id', $id)->get();
      $dowithdraw->withdraw = '1';
      $dowithdraw->save();
      return response()->json($dowithdraw,200);
    }
    
    你知道我的错误在哪里,怎么纠正吗


    不要将列表作为GET参数发送,而是作为POST发送:

    let params = {}
    params.ids = this.checkedNumbers
    
    axios.post(`/api/withdrawbutton/`, params)
        .then(response => {
           this.income[index].withdraw = '1'
           this.$forceUpdate()
       });
    
    控制器 路线
    我不认为您需要更新前面的任何内容,因为您已经检查了它们(如果您想保持检查状态)

    嗨,我收到了这个错误
    “消息”:“Method Illumb\\Database\\Eloquent\\Collection::update不存在。”,“exception”:“BadMethodCallException”,
    我很抱歉。我将编辑我的答案。正如您所知,我删除了
    get()
    并将其放在返回的json上。现在,我得到了带有此响应的代码200
    []
    ,并且在我的控制台中出现了以下错误:
    [Vue warn]:属性或方法“index”未在实例上定义,而是在呈现期间引用的。通过初始化属性
    未捕获(承诺中),确保此属性在数据选项中或对于基于类的组件是被动的类型错误:无法读取未定义的属性“未定义”
    需要提及我获得的状态200,但我的数据库不会更改您的
    可填充的
    模型中是否有
    撤消
    属性?
    let params = {}
    params.ids = this.checkedNumbers
    
    axios.post(`/api/withdrawbutton/`, params)
        .then(response => {
           this.income[index].withdraw = '1'
           this.$forceUpdate()
       });
    
    public function withdrawbutton(Request $request)
    {
      $dowithdraws = Income::whereIn('id', $request->input('ids', []));
      $dowithdraws->update(['withdraw' => '1']);
    
      return response()->json($dowithdraws->get(), 200);
    }
    
    Route::post('withdrawbutton/', 'IncomeController@withdrawbutton');