Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/252.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Laravel select left连接新数组索引中的所有列_Php_Mysql_Database_Laravel - Fatal编程技术网

Php Laravel select left连接新数组索引中的所有列

Php Laravel select left连接新数组索引中的所有列,php,mysql,database,laravel,Php,Mysql,Database,Laravel,我在laravel查询和搜索中有一个问题,但在google中找不到 这是我的问题: $data = DB::table('event') ->where('TU', '!=', null) ->where('TM', '!=', 180) ->leftJoin('market', 'event.event_id', '=', 'market.event_id') ->select([

我在laravel查询和搜索中有一个问题,但在google中找不到

这是我的问题:

$data = DB::table('event')
        ->where('TU', '!=', null)
        ->where('TM', '!=', 180)
        ->leftJoin('market', 'event.event_id', '=', 'market.event_id')
        ->select([
            'event.event_id as id',
            'TU',
            DB::raw('(TM*60+TS) as elapsed'),
            'markets' => 'market.*'
        ])
        ->orderBy('event.time', 'ASC')
        ->get();
Collection {#380 ▼
  #items: array:3 [▼
    0 => {#381 ▼
      +"id": 629
      +"TU": 0
      +"elapsed": 1200
      +"default": 1
      +"group_name": "other"
      +"api_updated_at": null
      +"updated_at": "2020-01-31 11:16:11"
    }
    1 => {#382 ▶}
    2 => {#385 ▶}
  ]
}
Collection {#380 ▼
  #items: array:3 [▼
    0 => {#381 ▼
      +"id": 629
      +"TU": 0
      +"elapsed": 1200
      +"markets": array:3 [▼
        0 => {#382 ▼
          +"default": 1
          +"group_name": "other"
          +"api_updated_at": null
          +"updated_at": "2020-01-31 11:16:11"
        }
        1 => {#383 ▶}
        2 => {#384 ▶}
      ]
    }
  ]
}
我的结果是:

$data = DB::table('event')
        ->where('TU', '!=', null)
        ->where('TM', '!=', 180)
        ->leftJoin('market', 'event.event_id', '=', 'market.event_id')
        ->select([
            'event.event_id as id',
            'TU',
            DB::raw('(TM*60+TS) as elapsed'),
            'markets' => 'market.*'
        ])
        ->orderBy('event.time', 'ASC')
        ->get();
Collection {#380 ▼
  #items: array:3 [▼
    0 => {#381 ▼
      +"id": 629
      +"TU": 0
      +"elapsed": 1200
      +"default": 1
      +"group_name": "other"
      +"api_updated_at": null
      +"updated_at": "2020-01-31 11:16:11"
    }
    1 => {#382 ▶}
    2 => {#385 ▶}
  ]
}
Collection {#380 ▼
  #items: array:3 [▼
    0 => {#381 ▼
      +"id": 629
      +"TU": 0
      +"elapsed": 1200
      +"markets": array:3 [▼
        0 => {#382 ▼
          +"default": 1
          +"group_name": "other"
          +"api_updated_at": null
          +"updated_at": "2020-01-31 11:16:11"
        }
        1 => {#383 ▶}
        2 => {#384 ▶}
      ]
    }
  ]
}
我希望将市场表中的所有列推送到结果中的一个索引中

像这样:

$data = DB::table('event')
        ->where('TU', '!=', null)
        ->where('TM', '!=', 180)
        ->leftJoin('market', 'event.event_id', '=', 'market.event_id')
        ->select([
            'event.event_id as id',
            'TU',
            DB::raw('(TM*60+TS) as elapsed'),
            'markets' => 'market.*'
        ])
        ->orderBy('event.time', 'ASC')
        ->get();
Collection {#380 ▼
  #items: array:3 [▼
    0 => {#381 ▼
      +"id": 629
      +"TU": 0
      +"elapsed": 1200
      +"default": 1
      +"group_name": "other"
      +"api_updated_at": null
      +"updated_at": "2020-01-31 11:16:11"
    }
    1 => {#382 ▶}
    2 => {#385 ▶}
  ]
}
Collection {#380 ▼
  #items: array:3 [▼
    0 => {#381 ▼
      +"id": 629
      +"TU": 0
      +"elapsed": 1200
      +"markets": array:3 [▼
        0 => {#382 ▼
          +"default": 1
          +"group_name": "other"
          +"api_updated_at": null
          +"updated_at": "2020-01-31 11:16:11"
        }
        1 => {#383 ▶}
        2 => {#384 ▶}
      ]
    }
  ]
}

请帮助我在laravel中编辑查询

您不能在select中使用一个字段而不是一个表中的多个字段。你可以试着用

->select([
        'event.event_id as id',
        'TU',
        DB::raw('(TM*60+TS) as elapsed'),
        'market.*'
    ])
或者将
与('market')
一起使用,而不是
leftjoin