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 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计