首页 > 解决方案 > Laravel - 用 table2 列更新 table1 列

问题描述

我想在迁移脚本中使用这种查询。

update table1, table2 set table1.column = table2.another_column where table1.id=table2.foreign_id

如何以 laravel/雄辩的方式做到这一点?

标签: laravel-5eloquent

解决方案


试试这个:

DB::table('table1')
    ->join('table2', 'table1.id', 'table2.foreign_id')
    ->update(['table1.column' => DB::raw('table2.another_column')]);

推荐阅读