dongwu1410 2016-12-16 16:03
浏览 180
已采纳

AJAX将数据发送到控制器,如何更新正确的ID?

I am using ajax to post data to the controller and I need to update the record based on the id I pass through. How would I go about this with Laravel Eloquent? Here is the controller...I know the data is being passed to the controller correctly just don't know how to update based on the id I send. Thank you for your help.

public function home(Request $request) {

$updateCus = New Customer($request->all());
$updateCus->update()->where('id', $request['id']);

}
  • 写回答

3条回答 默认 最新

  • doubaomao9304 2016-12-16 16:06
    关注

    Correct syntax is:

    Customer::where('id', $request->id)->update([
        'name' => $request->name,
        'country' => $request->country,
    ]);
    

    Or, if you want to update many columns:

    Customer::where('id', $request->id)->update($request->all());
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 如何用Thoony写ESP32温湿度检测无源蜂鸣器报警代码?
  • ¥20 部件内部的CT图像数据集
  • ¥15 Visual studio调用动态库
  • ¥15 双目摄像头标定后的校准文件
  • ¥15 powerbi矩阵增加度量值后出现对应关系错乱
  • ¥30 频率分析法分析绘制奈奎斯特图、波特图
  • ¥15 弹出来一万个系统找不到指定的文件框框,怎么解决
  • ¥15 ADS生成的微带线为什么是蓝色空心的
  • ¥15 求一下解题思路,完全不懂
  • ¥15 tensorflow