Laravel BACK PACK管理面板匿名全局范围使用

问题描述

Laravel BACK PACK管理面板。我想使用匿名全局范围。这里是link我有两个表(users,accounts_profiles) 在下面的屏幕快照中,您可以在accounts_profiles中看到一列user_id。

ACCOUNT PROFILE TABLE USER TABALE

首先,让我解释一下。 该代码我确实放在用户模型中。

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

这给了我管理面板中的记录。(因为我只获取user_id“ 1”记录) RECORDS

但是现在我想在两个表(用户,accounts_profiles)之间联接。 我知道我们将在用户模型中编写查询

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

但我收到该错误

response_message: [
{
code: 9997,message: "sqlSTATE[42702]: Ambiguous column: 7 ERROR: column reference "id" is ambiguous LINE 1: ...s"."id" = "accounts_profiles_biz"."user_id" where "id" = $1 ... ^ (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 limit 1),File: D:\xampp\htdocs\laravel\vendor\laravel\framework\src\Illuminate\Database\Connection.PHP,Line: 669",Exception Code: "sqlSTATE[42702]: Ambiguous column: 7 ERROR: column reference "id" is ambiguous LINE 1: ...s"."id" = "accounts_profiles_biz"."user_id" where "id" = $1 ... ^ (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 limit 1)"
}
]

非常感谢您。

解决方法

let date = Date()
// current,here: "Sep 30,2020 at 9:27 AM"

let distantPast = Date.distantPast
// "Jan 1,1 at 12:53 AM"

let distantFuture = Date.distantFuture
// "Jan 1,4001 at 1:00 AM"

[其中“ id” = 1],此ID不明确,请检查您的$ builder。

建议使用雄辩的ORM范围

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...