Php 如何将表作为第二级联接
我有一个包含6000多行的表,我需要“获取”这些行作为与其他表的连接。 我希望这次加入成为第一级的“第二级”。 有办法吗? (没有雄辩的口才,这使它变得非常缓慢…) 例如:Php 如何将表作为第二级联接,php,mysql,laravel,laravel-5,join,Php,Mysql,Laravel,Laravel 5,Join,我有一个包含6000多行的表,我需要“获取”这些行作为与其他表的连接。 我希望这次加入成为第一级的“第二级”。 有办法吗? (没有雄辩的口才,这使它变得非常缓慢…) 例如: $query = DB::table('first_table') ->join('second_table', 'first_table.id', '=', 'second_table.first_id') ->get(); 我从中得到的是: [0] => [ [id] => 1
$query = DB::table('first_table')
->join('second_table', 'first_table.id', '=', 'second_table.first_id')
->get();
我从中得到的是:
[0] => [
[id] => 1
[info] => true
[first_id] => 1
[something] => 929
]
[1] => [
[id] => 2
[info] => true
[first_id] => 2
[something] => 1212
]
[2] => [
[id] => 3
[info] => true
[first_id] => 2
[something] => 4444
]
我想要得到的是:
[0] => [
[id] => 1
[info] => true
[second_table] => [
[first_id] => 1
[something] => 929
]
]
[1] => [
[id] => 2
[info] => true
[second_table] => [
[first_id] => 2
[something] => 1212
]
]
[2] => [
[id] => 3
[info] => true
[second_table] => [
[first_id] => 2
[something] => 4444
]
]
查询总是只返回记录,而不是多个级别。如果你想像那样格式化数据,你必须自己映射它。这基本上就是Eloquent为您所做的,但需要更多的查询。您是否为
first_table
和second_table
设置了Eloquent模型?@Rwd Eloquent模型的问题是它的工作非常复杂slow@philipxy什么?