php - Laravel BACK PACK admin panel. Anonymous Global scopes Use

Laravel BACK PACK admin panel. i want to use Anonymous Global scopes. here is link. I have two tables (users , accounts_profiles) in below screenshot you can see in accounts_profiles we have a column of user_id.
ACCOUNT PROFILE TABLE USER TABALE
first , let me explain you. That code I do put in User Model.
protected static function boot(){
parent::boot();
$userId = 1;
static::addGlobalScope('users', function (Builder $builder) use ($userId) {
return $builder->where('users.id', $userId);
});
}
And that gave me that record in admin panel.( because i'm fetching only user_id "1" record) RECORDS
but now I want to join between two tables( users , accounts_profiles). I know we will write query in User Model.
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');
});
}
but im getting that Error.
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)"
}
]
Thank you so much.
Answer
Solution:
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
[where "id"=1] ,this id is ambiguous, check your $builder .
Eloquent ORM scope is recommended
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: npm err! code 1
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.