PHP,JOIN和Laravel-连接表时如何分隔数组

时间:2018-12-31 06:03:41

标签: php mysql sql laravel join

如何分隔此联接表?因为当我获取数据时,所有字段都被合并了。我怎样才能将表作为数组分开?就我而言,我的两个表上的所有字段都在这里合并,这就是我的代码。

$getairId = DB::table('aircrafts')
  ->join('movies','movies.aircraft_id','=','aircrafts.aircraft_id')
  ->join('ads','ads.aircraft_id','=','aircrafts.aircraft_id')
  ->select('movies.*','ads.*')
  ->where('aircrafts.aircraft_id','=', $airid)
  ->get();

1 个答案:

答案 0 :(得分:0)

use aloquent with method

例如:

$users = User::with('podcasts')->get();

或者,如果您不想使用口语,则可以像这样将它们分开:

$getairId = DB::table('aircrafts')
 ->join('movies','movies.aircraft_id','=','aircrafts.aircraft_id')
 ->join('ads','ads.aircraft_id','=','aircrafts.aircraft_id')
 ->select('movies.*','ads.*', 'movies.id as movies_id', 'ads.id as ads_id')
 ->where('aircrafts.aircraft_id','=', $airid)
 ->get();