1

how can I separate this join table? because when I fetch the data all fields are combined. how can i separate table to table as an array? in my case all fields on my two tables are combining here is my code.

$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
    You can use the With method to fetch data of other table in separate array. For more detail you can check this link. https://stackoverflow.com/questions/19852927/get-specific-columns-using-with-function-in-laravel-eloquent – Bhavin Thummar Dec 31 '18 at 06:10
  • i think i dont need eloquent on this situation i just need the array i have an output on my query but still i have no idea how to separate them by table because my problem was when i join query them they are combining and not separated they are only in one table –  Dec 31 '18 at 06:16
  • As I know there is no way to do it with query builder. You should loop through results and format it in desired way if you don't use eloquent. Maybe this could help https://stackoverflow.com/questions/41673556/laravel-nesting-query-join-results-in-a-sub-array – Jakob Dec 31 '18 at 08:49

1 Answers1

0

use aloquent with method

for example :

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

Or if you don't want to use aloquent you can just separate them like this:

$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();
m.elewa
  • 187
  • 1
  • 9