如何使用laravel eloquent的where子句将数据插入db?

时间:2016-10-10 13:36:34

标签: laravel laravel-5.3

我正在使用此语句插入数据。

if(\App\tempLogin::insert(['otp'=>$otp])->where('mobile','=',$mobile))
  return 1;

但我收到错误“字段'用户名'没有默认值(SQL:插入tempLoginotp)值(8673))”

1 个答案:

答案 0 :(得分:1)

您需要使用\App\tempLogin::where('mobile', $mobile)->update(['otp' => $otp]); 方法更新现有数据库行中的信息:

insert()

{{1}}创建新行。