Skip to main content

Limits and Usage

When a plan feature is a numeric limit — such as projects: 5 or api_calls: 10000 — you can track consumption against that limit and enforce it in your application.

Reading a limit

use Pixelworxio\Subscribd\Facades\Entitlements;

$limit = Entitlements::for($user)->limit('projects');
// int — e.g. 5
// null — unlimited (feature value is null in the plan config)
// 0 / false — feature is not available

Checking remaining capacity

$used      = $user->projects()->count();
$limit     = Entitlements::for($user)->limit('projects');
$remaining = $limit === null ? INF : max(0, $limit - $used);

if ($remaining === 0) {
    abort(403, 'Project limit reached. Upgrade your plan to add more.');
}

Plan feature configuration reference

// config/subscribd.php
'plans' => [
    'free' => [
        'features' => [
            'projects'  => 2,      // hard limit of 2
            'api_calls' => 10000,  // hard limit of 10,000
            'exports'   => false,  // not available
        ],
    ],
    'pro' => [
        'features' => [
            'projects'  => null,   // unlimited
            'api_calls' => null,   // unlimited
            'exports'   => true,
        ],
    ],
],

Enforcing limits in a controller

public function store(Request $request): Response
{
    $limit = Entitlements::for($request->user())->limit('projects');

    if ($limit !== null && $request->user()->projects()->count() >= $limit) {
        return response()->json(['error' => 'Project limit reached.'], 403);
    }

    // Proceed with creation
}

Enforcing limits in a policy

public function create(User $user): bool
{
    $limit = Entitlements::for($user)->limit('projects');

    return $limit === null || $user->projects()->count() < $limit;
}

Next steps