Laravel 8 更新
当然, 除了插入记录到数据库中,查询构造器也可以通过 update 方法更新已有的记录。 update 方法和 insert 方法一样,接受包含要更新的字段及值的数组。你可以通过 where 子句对 update 查询进行约束:
$affected = DB::table('users')
->where('id', 1)
->update(['votes' => 1]);
当然, 除了插入记录到数据库中,查询构造器也可以通过 update 方法更新已有的记录。 update 方法和 insert 方法一样,接受包含要更新的字段及值的数组。你可以通过 where 子句对 update 查询进行约束:
$affected = DB::table('users')
->where('id', 1)
->update(['votes' => 1]);