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 shape_predictor_68_face_landmarks.dat
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料