【问题标题】:how to update column of table by each element of array one by one?如何通过数组的每个元素一个一个地更新表的列?
【发布时间】:2021-06-26 10:39:59
【问题描述】:

我想更新表格的列

$update = DB::table('users')->where('latehours' , '');

foreach($update as $up) {
    $up->update([
        'latehours' => $total_hours
    ]);
}

【问题讨论】:

  • \Illuminate\Database\Eloquent\Builder 不可迭代。你的意思是DB::table('users')->where('latehours' , '')->get()

标签: mysql arrays laravel string controller


【解决方案1】:

您可以直接更新您的表,而无需从数据库中获取数据:

$updated = DB::table('users')->where('latehours', '')
                             ->update(['latehours' => $total_hours]);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-05-29
    • 1970-01-01
    • 2020-08-21
    • 2015-08-15
    • 2021-11-09
    • 2018-06-25
    • 1970-01-01
    相关资源
    最近更新 更多