'array', 'is_active' => 'boolean', ]; /** * Get devices in this group */ public function devices(): HasMany { return $this->hasMany(Device::class, 'group_id'); } /** * Get users who have access to this group */ public function users(): BelongsToMany { return $this->belongsToMany(User::class, 'device_group_user', 'device_group_id', 'user_id'); } /** * Scope for active groups */ public function scopeActive($query) { return $query->where('is_active', true); } /** * Get device count in this group */ public function getDeviceCountAttribute(): int { return $this->devices()->count(); } }