Laravel GraphQL,其中选择子查询

Laravel GraphQL,其中选择子查询,laravel,graphql,laravel-lighthouse,Laravel,Graphql,Laravel Lighthouse,这些天,我用Laravel框架,Lighthouse Library学习了GraphQL。 我试过做一种选择查询 因此,我想知道GraphQL能否选择下面的SQL查询 SELECT * FROM TABLE_A WHERE type=1 AND chart_id=(SELECT id FROM TABLE_B WHERE phone='0000~~') 我希望客户首先从这个查询中得到结果 SELECT id FROM TABLE_B WHERE phone='0000~~' 然后再进行第二次

这些天,我用Laravel框架,Lighthouse Library学习了GraphQL。 我试过做一种选择查询

因此,我想知道GraphQL能否选择下面的SQL查询

SELECT * FROM TABLE_A WHERE type=1 AND chart_id=(SELECT id FROM TABLE_B WHERE phone='0000~~')
我希望客户首先从这个查询中得到结果

SELECT id FROM TABLE_B WHERE phone='0000~~'
然后再进行第二次查询,我想我可以得到一个结果

但我想知道我能从一个请求中得到结果。谢谢。

您可以尝试以下内容

 $phoneNumber = '0000~~';

 $data = DB::table('tableA')->where('type',1)
            ->whereIn('chart_id',function($query) use ($phoneNumber) {
                $query->select('id')
                      ->from('tableB')
                     ->where('phone', '=',$phoneNumber);
         })->get();
 TableA::where('type',1)
        ->whereHas('tableBRelationshipName', function ($q) use ($phoneNumber) {
             $q->select('id')
             $q->where('phone','=',$phoneNumber);
 })->get();
如果表A和表B之间存在关系,您可以执行以下操作

 $phoneNumber = '0000~~';

 $data = DB::table('tableA')->where('type',1)
            ->whereIn('chart_id',function($query) use ($phoneNumber) {
                $query->select('id')
                      ->from('tableB')
                     ->where('phone', '=',$phoneNumber);
         })->get();
 TableA::where('type',1)
        ->whereHas('tableBRelationshipName', function ($q) use ($phoneNumber) {
             $q->select('id')
             $q->where('phone','=',$phoneNumber);
 })->get();

表A和表B之间有什么关系吗?@Mikeros是的。TableA有外键,外键名为chart\u id。chart\u id是TableB的键