我希望从laravel中的表中获取选定的字段,以便在变量中分配我的表字段。但它总是会给我一些数据库查询错误,我在这里添加了我的代码。当我使用直接字段而不是赋值给变量时,这种方法工作得很好
$selectedfields = "'table1.*', 'table2.*','table3.column'"
$data = DB::table('table1')
->select($selectedfields)->get();发布于 2021-02-10 12:24:13
您可以使用DB:raw
$selectedfields = 'table1.*, table2.*, table3.column';
$data = DB::table('table1')
->select(DB::raw($selectedfields))->get();您可能还需要连接表。
发布于 2021-02-10 12:21:38
查询应该是这样的
$data = DB::table('table1')
->join('table2','table2.id','=','table1.id')
->join('table3','table3.id','=','table1.id')
->select('table1.*','table2.*','table3.*')->get();https://stackoverflow.com/questions/66130785
复制相似问题