'datetime', 'password' => 'hashed']; public function role() { return $this->belongsToMany(Role::class, 'role_user')->withTimestamps(); } public function hasRole(string $role): bool { $this->loadMissing('role'); return $this->role->contains('name', $role); } public function tenant() { return $this->belongsTo(Tenant::class); } public function licenseAssignments() { return $this->hasMany(LicenseAssignment::class); } public function children() { return $this->belongsToMany(User::class, 'parent_child', 'parent_id', 'child_id') ->using(ParentChild::class) ->withTimestamps() ->withoutGlobalScope(\App\Scopes\TenantScope::class); } public function parents() { return $this->belongsToMany(User::class, 'parent_child', 'child_id', 'parent_id') ->using(ParentChild::class) ->withTimestamps() ->withoutGlobalScope(\App\Scopes\TenantScope::class); } protected static function booted(): void { static::deleting(function (User $user) { if ($user->isForceDeleting()) { return; // FK cascadeOnDelete handles hard-delete } \DB::table('role_user')->where('user_id', $user->id)->delete(); \DB::table('license_assignments')->where('user_id', $user->id)->delete(); \DB::table('parent_child') ->where('parent_id', $user->id) ->orWhere('child_id', $user->id) ->delete(); }); } }