Laravel,带连接的匿名全局范围

Laravel, Anonymous Global scopes with joins

使用匿名全局范围。我收到一个错误。 这是我的代码,

protected static function boot(){
    parent::boot();
    $userId = 1;
    static::addGlobalScope('users', function (Builder $builder) use ($userId) {
     $builder->join("accounts_profiles_biz", 'users.id', '=', 'accounts_profiles_biz.user_id')->where('users.user_id', $userId);
    });
}

这里有错误

Exception Code: "SQLSTATE[42702]: Ambiguous column: 7 ERROR: column reference "id" is ambiguous LINE 1: ...s"."id" = "accounts_profiles_biz"."user_id" where "id" =  ... ^ (SQL: select * from "users" inner join "accounts_profiles_biz" on "users"."id" = "accounts_profiles_biz"."user_id" where "id" = 1 and "users"."deleted_at" is null and "users"."user_id" = 1 limit 1)"

我认为问题在这一行:

  $builder->join("accounts_profiles_biz", 'users.id', '=', 
'accounts_profiles_biz.user_id')->where('users.user_id', $userId);

users.user_id 列不存在,我认为..

应该是:

  $builder->join("accounts_profiles_biz", 'users.id', '=', 'accounts_profiles_biz.user_id')

->where('users.id', $userId);