> ## Documentation Index
> Fetch the complete documentation index at: https://docs.subscribd.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Class-Based Features

> Type-safe feature checking with dedicated feature classes

# Class-Based Features

Instead of referencing feature keys as magic strings like `'exports'` or `'projects'`, you can define feature classes for type safety, IDE autocompletion, and safe refactoring.

## Creating a feature class

Implement `Pixelworxio\Subscribd\Contracts\Feature`:

```php theme={null}
<?php

namespace App\Features;

use Pixelworxio\Subscribd\Contracts\Feature;

class ExportsFeature implements Feature
{
    public function key(): string
    {
        return 'exports';
    }
}
```

## Checking with a feature class

Pass the class or an instance directly to `allows()` and `limit()`:

```php theme={null}
use App\Features\ExportsFeature;
use App\Features\ProjectsFeature;
use Pixelworxio\Subscribd\Facades\Entitlements;

Entitlements::for($user)->allows(ExportsFeature::class);      // bool
Entitlements::for($user)->allows(new ExportsFeature());       // same

Entitlements::for($user)->limit(ProjectsFeature::class);      // int|null
```

## Feature class with a default limit

Define a default limit on the class itself. When the plan does not specify a value for the feature, this default is used as a fallback:

```php theme={null}
<?php

namespace App\Features;

use Pixelworxio\Subscribd\Contracts\Feature;

class ProjectsFeature implements Feature
{
    public function key(): string
    {
        return 'projects';
    }

    public function default(): int
    {
        return 1; // free users get 1 project if no plan feature is defined
    }
}
```

## Organising feature classes

A simple approach is a `App\Features\` namespace with one class per feature:

```
app/
└── Features/
    ├── ExportsFeature.php
    ├── ProjectsFeature.php
    ├── ApiAccessFeature.php
    └── SupportTierFeature.php
```

## Next steps

* **[Checking Features](/entitlements/checking-features)** — String-based feature checks
* **[Limits and Usage](/entitlements/limits-and-usage)** — Tracking usage against limits
