Q:

Laravel 5.4 Eager loading belongsToMany Relationship null Binding

I have an existing model that is lazy loading a belongsToMany relationship just fine.
My problem is, when i try to eager load the relationship, i get an empty result.
When I inspect the query, it shows that the binding for the relationship query is null.
Here is my (simplified) code:
// Controller
public function filter(Request $request, App\Programs $program)
{
    $program = $program->newQuery();

    $program->select(
            'slug',
            'title',
            'season'
    );

    $program->with([
        'sports'
    ]);
    return $program->get();
}

// Model
class Programs extends Model
{
    public function sports(){
        return $this->belongsToMany('App\Sport', 'program_sport', 'program_id', 'sport_id');
    }

}

A:

The problem is that you don't take id from database so Eloquent cannot get related models. Instead of:
 $program->select(
            'slug',
            'title',
            'season'
    );

you should use:
 $program->select(
            'id',
            'slug',
            'title',
            'season'
    );

Be aware however you could use simpler syntax (and don't inject model in controller like this):
return Program::select('id','slug', 'title', 'season')->with('sports')->get();

Also I have no idea why you use route model binding in that case

