'datetime', 'password' => 'hashed']; public function role() { return $this->belongsToMany(Role::class, 'role_user')->withTimestamps(); } public function hasRole(string $role): bool { return $this->role()->where('roles.name', $role)->exists(); } 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) { // Soft-delete cascade: DB foreign key cascades don't fire on soft-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(); }); } }