update api register
This commit is contained in:
+35
-2
@@ -36,6 +36,7 @@ class User extends Authenticatable
|
||||
'profile_photo_file_id',
|
||||
'password',
|
||||
'is_master',
|
||||
'is_platform_staff',
|
||||
'access_level',
|
||||
'status',
|
||||
'verification_channel',
|
||||
@@ -66,6 +67,7 @@ class User extends Authenticatable
|
||||
'email_verified_at' => 'datetime',
|
||||
'password' => 'hashed',
|
||||
'is_master' => 'boolean',
|
||||
'is_platform_staff' => 'boolean',
|
||||
'access_level' => UserAccessLevel::class,
|
||||
'verification_code_expires_at' => 'datetime',
|
||||
'verified_at' => 'datetime',
|
||||
@@ -112,14 +114,45 @@ class User extends Authenticatable
|
||||
return $this->morphMany(Wallet::class, 'owner');
|
||||
}
|
||||
|
||||
public function voucherAgents()
|
||||
{
|
||||
return $this->hasMany(VoucherAgent::class);
|
||||
}
|
||||
|
||||
public function roleApplications()
|
||||
{
|
||||
return $this->hasMany(RoleApplication::class, 'applicant_user_id');
|
||||
}
|
||||
|
||||
public function linkedCustomers()
|
||||
{
|
||||
return $this->belongsToMany(Customer::class, 'customer_user_links')->withPivot(['tenant_id', 'relationship', 'is_primary'])->withTimestamps();
|
||||
}
|
||||
|
||||
public function isMasterAdmin(): bool
|
||||
{
|
||||
return $this->is_master || $this->access_level === UserAccessLevel::MASTER_ADMIN;
|
||||
}
|
||||
|
||||
public function isTenantOwner(): bool
|
||||
public function isTenantOwner(?int $tenantId = null): bool
|
||||
{
|
||||
return $this->access_level === UserAccessLevel::TENANT_OWNER;
|
||||
if ($this->access_level !== UserAccessLevel::TENANT_OWNER) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->userTenants()
|
||||
->where('role', 'tenant_owner')
|
||||
->when($tenantId, fn ($query) => $query->where('tenant_id', $tenantId))
|
||||
->exists();
|
||||
}
|
||||
|
||||
public function tenantRole(?int $tenantId): ?string
|
||||
{
|
||||
if (! $tenantId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->userTenants()->where('tenant_id', $tenantId)->value('role');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user