想在不知道其他 Table 姓名 Laravel 的情况下加入两个 table

Want to Join Two table without Knowing other Table Name Laravel

$users = DB::table('table1')->where('id', '=', '1')->get();

$joinedtable = DB::table('table1')
->join('' . $users[0]->tablename . '', 'table1.id', '=', '' . $users[0]->tablename . '.id')
->get();

我想加入两个 table,第一个 table 名称已给出,第二个来自 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
                )

        )

第一个解决方案选项

使用pluck()获得table名字然后加入tables。

$table2 = DB::table('table1')->where('id', '=', '1')->pluck('columnname');