$users = DB::table('table1')->where('id', '=', '1')->get();
$joinedtable = DB::table('table1')
->join('' . $users[0]->tablename . '', 'table1.id', '=', '' . $users[0]->tablename . '.id')
->get();
我想加入两个表,给出第一个表名,第二个来自table1。我想缩短此查询并希望使用一个查询完成。是否可能
当前O / P
[items:protected] => Array
(
[0] => stdClass Object
(
[id] => 1
[country] => table2
[test1] => 23423
[test2] => 234234
[newdata1] => 1
[newdata2] => 1
[newdata3] => 1
)
[1] => stdClass Object
(
[id] => 2
[country] => table3
[test1] => 123
[test2] => 123
[newdata1] => 2
[newdata2] => 2
[newdata3] => 2
)
)
答案 0 :(得分:0)
第一个解决方案选项
使用pluck()
获取表名,然后加入表。
$table2 = DB::table('table1')->where('id', '=', '1')->pluck('columnname');