MySQL/Eloquent force id by left join even if null

MySQL/Eloquent force id by left join even if null

I have this query wrote in Eloquent :

I have this query wrote in Eloquent :

    return TypeModel::with(['apt' => function($q) use ($id){
        $q->leftJoin('build_apt', function($join) use($id){
            $join->on('build_apt.id_apt', '=', 'apt.id_apt');
            $join->on('build_apt.id_build', '=', DB::raw($id->id_build));
        })
    }])
    ->get()
    ->toJson();

Equivalent SQL :

SELECT * 
FROM `apt` 
LEFT JOIN `build_apt` 
    ON  `build_apt`.`id_apt` = `apt`.`id_apt` 
    AND `build_apt`.`id_build` = 1 
WHERE `apt`.`id_typeapt` in (1, 2, 3, 4, 5)

I have the result I need except one thing, the id given is null :

[
    {"id_typeapt":1,"apt":[
        {"id_apt":null,"image_apt":"apt_1.png"}, 
        {"id_aptitude":null,"image_apt":"apt_2.png"}
    ]
]

How can I force it to look for the id from the table "apt" and not giving me "null" as a result?

Thanks you!

EDIT : Where clause is coming from the with

public function apt(){
    return $this->hasMany(AptModel::class, 'id_typeapt', 'id_typeapt');
}

EDIT2 :

id_apt was crushed by the other id_apt with a simple rename I could retrieve the id :

    return TypeModel::with(['apt' => function($q) use ($id){
        $q->leftJoin('build_apt', function($join) use($id){
            $join->on('build_apt.id_apt', '=', 'apt.id_apt');
            $join->on('build_apt.id_build', '=', DB::raw($id->id_build));
        })
    }])->select(DB::raw("*, apt.id_apt as id_apt);
  }])


Angular 9 Tutorial: Learn to Build a CRUD Angular App Quickly

What's new in Bootstrap 5 and when Bootstrap 5 release date?

Brave, Chrome, Firefox, Opera or Edge: Which is Better and Faster?

How to Build Progressive Web Apps (PWA) using Angular 9

What is new features in Javascript ES2020 ECMAScript 2020

Laravel 5.8 Tutorial: Build your First CRUD App with Laravel and MySQL (PHP 7.1+)

Laravel 5.8 Tutorial: Build your First CRUD App with Laravel and MySQL (PHP 7.1+)

Building PHP apps using SQL Server on Windows

3 step: Building PHP apps using SQL Server on Windows

PhP MySQL Projects

Simpliv LLC, a platform for learning and teaching online courses. We basically focus on online learning which helps to learn business concepts, software technology to develop personal and professional goals through video library by recognized industry experts and trainers.