PHPackages                             cleaniquecoders/package-subscription - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. cleaniquecoders/package-subscription

ActiveLibrary

cleaniquecoders/package-subscription
====================================

This is my package package-subscription

1.1.0(1mo ago)12[2 PRs](https://github.com/cleaniquecoders/package-subscription/pulls)MITPHPPHP ^8.3CI passing

Since Dec 7Pushed 1mo agoCompare

[ Source](https://github.com/cleaniquecoders/package-subscription)[ Packagist](https://packagist.org/packages/cleaniquecoders/package-subscription)[ Docs](https://github.com/cleaniquecoders/package-subscription)[ GitHub Sponsors]()[ RSS](/packages/cleaniquecoders-package-subscription/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)Dependencies (26)Versions (6)Used By (0)

Package Subscription Management for Laravel
===========================================

[](#package-subscription-management-for-laravel)

[![Latest Version on Packagist](https://camo.githubusercontent.com/bd11a285ee20b4792a9fb7d06fa8d7e706a1019501e4d72c099a3b2456301001/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f636c65616e69717565636f646572732f7061636b6167652d737562736372697074696f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/cleaniquecoders/package-subscription)[![GitHub Tests Action Status](https://camo.githubusercontent.com/a48c5596fc5072916169527ce21c2422b16f4e6714dfc3d1bd5746c83d1e586a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f636c65616e69717565636f646572732f7061636b6167652d737562736372697074696f6e2f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/cleaniquecoders/package-subscription/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/1f636fd9621029916dbeb3291f522473a18d6a693ee9ca080f3a6305570ddce7/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f636c65616e69717565636f646572732f7061636b6167652d737562736372697074696f6e2f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/cleaniquecoders/package-subscription/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/c43d0541175ffe4addda048b30afc687e8619a153e68a173c8ccd4ced70593bd/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f636c65616e69717565636f646572732f7061636b6167652d737562736372697074696f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/cleaniquecoders/package-subscription)

A comprehensive Laravel package for managing subscription plans and subscriptions in SaaS applications. This package provides an easy-to-configure solution for implementing package-based subscription management, allowing you to create flexible pricing tiers, manage user subscriptions, track usage, and handle the complete subscription lifecycle.

Documentation
-------------

[](#documentation)

For complete documentation, see the [docs](./docs/README.md) directory:

- [Architecture](./docs/01-architecture/README.md) - System design and components
- [Development](./docs/02-development/README.md) - Installation, configuration, and testing
- [Usage](./docs/03-usage/README.md) - Plan management, subscriptions, and access control
- [API Reference](./docs/04-api-reference/README.md) - Complete API documentation

Features
--------

[](#features)

### Plan Management

[](#plan-management)

- **Flexible Plan Configuration**: Create unlimited subscription plans with custom pricing, features, and limits
- **Plan Tiers**: Support for multiple pricing tiers (Free, Basic, Pro, Enterprise, etc.)
- **Feature Toggles**: Define feature access per plan for granular control
- **Usage Limits**: Set quotas and limits for each plan (API calls, storage, users, etc.)
- **Custom Metadata**: Attach custom attributes to plans for extended functionality

### Subscription Lifecycle

[](#subscription-lifecycle)

- **Subscribe**: Easy subscription creation with plan assignment
- **Renew**: Automatic and manual subscription renewal handling
- **Cancel**: Graceful subscription cancellation with end-of-period access
- **Suspend/Resume**: Temporarily pause and reactivate subscriptions
- **Trial Periods**: Configurable trial periods for new subscriptions
- **Grace Periods**: Allow access continuation during payment issues

### Billing &amp; Payments

[](#billing--payments)

- **Multiple Billing Periods**: Support for monthly, quarterly, yearly, and custom billing cycles
- **Proration**: Handle mid-cycle upgrades/downgrades with automatic proration
- **Metered Billing**: Track and bill based on usage metrics
- **Invoice Generation**: Generate subscription invoices and receipts
- **Payment Gateway Agnostic**: Works with any payment provider

### Plan Changes

[](#plan-changes)

- **Upgrades**: Seamless plan upgrades with immediate feature access
- **Downgrades**: Controlled downgrades with policy enforcement
- **Plan Switching**: Change between plans with customizable behavior
- **Proration Calculation**: Automatic credit/debit calculation for mid-cycle changes

### Usage Tracking

[](#usage-tracking)

- **Usage Monitoring**: Track feature usage against plan limits
- **Quota Management**: Enforce and monitor quotas in real-time
- **Usage Reports**: Generate usage statistics and reports
- **Overage Handling**: Define behavior when limits are exceeded
- **Reset Cycles**: Automatic usage counter resets per billing period

### Multi-Tenancy

[](#multi-tenancy)

- **Team/Organization Support**: Manage subscriptions per team or organization
- **User-based Subscriptions**: Individual user subscriptions
- **Flexible Ownership**: Support for various subscription ownership models

### Events &amp; Webhooks

[](#events--webhooks)

- **Subscription Events**: Fire events on subscription lifecycle changes
- **Usage Events**: Track usage-related events
- **Custom Hooks**: Extend functionality with custom event listeners
- **Integration Ready**: Easy integration with notification systems

### Developer Experience

[](#developer-experience)

- **Fluent API**: Intuitive, chainable methods for common operations
- **Eloquent Models**: Fully integrated with Laravel's Eloquent ORM
- **Query Scopes**: Pre-built query scopes for common filtering
- **Trait-based**: Easy integration with existing User/Team models
- **Comprehensive Tests**: Well-tested codebase with high coverage
- **Type-safe**: Full PHPStan Level 5 compliance

### Access Control

[](#access-control)

- **Feature Gates**: Check feature access based on active subscription
- **Middleware**: Protect routes based on subscription status
- **Blade Directives**: Conditionally render views based on plan features
- **API Throttling**: Rate limiting based on subscription tier

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require cleaniquecoders/package-subscription
```

You can publish and run the migrations with:

```
php artisan vendor:publish --tag="package-subscription-migrations"
php artisan migrate
```

You can publish the config file with:

```
php artisan vendor:publish --tag="package-subscription-config"
```

This is the contents of the published config file:

```
return [
];
```

Optionally, you can publish the views using

```
php artisan vendor:publish --tag="package-subscription-views"
```

Usage
-----

[](#usage)

### Setting Up Models

[](#setting-up-models)

Add the `HasSubscriptions` trait to your User or Team model:

```
use CleaniqueCoders\PackageSubscription\Concerns\HasSubscriptions;

class User extends Authenticatable
{
    use HasSubscriptions;

    // Your model code...
}
```

### Creating Plans

[](#creating-plans)

```
use CleaniqueCoders\PackageSubscription\Models\Plan;

// Create a basic plan
$basicPlan = Plan::create([
    'name' => 'Basic',
    'slug' => 'basic',
    'description' => 'Perfect for individuals',
    'price' => 9.99,
    'billing_period' => 'monthly',
    'features' => [
        'projects' => 10,
        'storage' => 5, // GB
        'api_calls' => 1000,
        'support' => 'email',
    ],
]);

// Create a pro plan
$proPlan = Plan::create([
    'name' => 'Pro',
    'slug' => 'pro',
    'description' => 'For growing teams',
    'price' => 29.99,
    'billing_period' => 'monthly',
    'trial_period_days' => 14,
    'features' => [
        'projects' => 50,
        'storage' => 50, // GB
        'api_calls' => 10000,
        'support' => 'priority',
        'custom_domain' => true,
    ],
]);
```

### Managing Subscriptions

[](#managing-subscriptions)

```
// Subscribe a user to a plan
$user->subscribeTo($basicPlan);

// Subscribe with trial period
$user->subscribeTo($proPlan, [
    'trial_ends_at' => now()->addDays(14),
]);

// Check if user has an active subscription
if ($user->hasActiveSubscription()) {
    // User is subscribed
}

// Check if user is subscribed to a specific plan
if ($user->subscribedTo('pro')) {
    // User is on the pro plan
}

// Get active subscription
$subscription = $user->activeSubscription();

// Cancel subscription
$user->activeSubscription()->cancel();

// Cancel at end of billing period
$user->activeSubscription()->cancelAtPeriodEnd();

// Resume a cancelled subscription
$user->activeSubscription()->resume();
```

### Plan Upgrades &amp; Downgrades

[](#plan-upgrades--downgrades)

```
// Upgrade to a higher plan
$user->activeSubscription()->upgradeTo($proPlan);

// Downgrade to a lower plan
$user->activeSubscription()->downgradeTo($basicPlan);

// Switch plans with custom options
$user->activeSubscription()->switchTo($proPlan, [
    'prorate' => true,
    'invoice_now' => false,
]);
```

### Feature Access Control

[](#feature-access-control)

```
// Check if user has access to a feature
if ($user->canUseFeature('custom_domain')) {
    // Feature is available in their plan
}

// Get feature limit
$projectLimit = $user->getFeatureLimit('projects'); // 10

// Check if within limits
if ($user->withinLimit('projects', $currentProjectCount)) {
    // User has not exceeded their project limit
}
```

### Usage Tracking

[](#usage-tracking-1)

```
// Record usage
$user->recordUsage('api_calls', 100);

// Get current usage
$apiUsage = $user->getUsage('api_calls');

// Check if usage exceeds limit
if ($user->exceedsLimit('api_calls')) {
    // User has exceeded their API call limit
}

// Get usage percentage
$percentage = $user->getUsagePercentage('storage'); // 0-100
```

### Middleware Protection

[](#middleware-protection)

Protect routes based on subscription status:

```
// In routes/web.php
Route::middleware(['subscribed'])->group(function () {
    Route::get('/dashboard', [DashboardController::class, 'index']);
});

// Require specific plan
Route::middleware(['subscribed:pro'])->group(function () {
    Route::get('/advanced-features', [AdvancedController::class, 'index']);
});

// Require feature access
Route::middleware(['feature:custom_domain'])->group(function () {
    Route::get('/domain-settings', [DomainController::class, 'index']);
});
```

### Blade Directives

[](#blade-directives)

```
@subscribed
    You have an active subscription!
@else
    Subscribe Now
@endsubscribed

@subscribedToPlan('pro')
    Access Pro Features
@endsubscribedToPlan

@feature('custom_domain')
    Configure Custom Domain
@endfeature
```

### Handling Events

[](#handling-events)

Listen to subscription events:

```
// In EventServiceProvider.php
use CleaniqueCoders\PackageSubscription\Events\SubscriptionCreated;
use CleaniqueCoders\PackageSubscription\Events\SubscriptionCancelled;
use CleaniqueCoders\PackageSubscription\Events\SubscriptionRenewed;

protected $listen = [
    SubscriptionCreated::class => [
        SendWelcomeEmail::class,
    ],
    SubscriptionCancelled::class => [
        SendCancellationEmail::class,
    ],
    SubscriptionRenewed::class => [
        SendRenewalReceipt::class,
    ],
];
```

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Nasrul Hazim Bin Mohamad](https://github.com/nasrulhazim)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

43

—

FairBetter than 90% of packages

Maintenance98

Actively maintained with recent releases

Popularity4

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 86.4% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~56 days

Total

3

Last Release

40d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/b57069d0f4b634f65eccc6e5d5848990e25968d45ec2cf46d626c6a4658f944b?d=identicon)[nasrulhazim.m](/maintainers/nasrulhazim.m)

---

Top Contributors

[![nasrulhazim](https://avatars.githubusercontent.com/u/10341422?v=4)](https://github.com/nasrulhazim "nasrulhazim (19 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (2 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (1 commits)")

---

Tags

laravelCleanique Coderspackage-subscription

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/cleaniquecoders-package-subscription/health.svg)

```
[![Health](https://phpackages.com/badges/cleaniquecoders-package-subscription/health.svg)](https://phpackages.com/packages/cleaniquecoders-package-subscription)
```

###  Alternatives

[vormkracht10/laravel-mails

Laravel Mails can collect everything you might want to track about the mails that has been sent by your Laravel app.

24149.7k](/packages/vormkracht10-laravel-mails)[spatie/laravel-prometheus

Export Laravel metrics to Prometheus

2651.3M6](/packages/spatie-laravel-prometheus)[ralphjsmit/laravel-helpers

A package containing handy helpers for your Laravel-application.

13704.6k2](/packages/ralphjsmit-laravel-helpers)[cleaniquecoders/shrinkr

Shrinkr is a Laravel package for shortening URLs, with custom slugs, analytics, branded domains, and seamless API integration.

142.9k](/packages/cleaniquecoders-shrinkr)[basillangevin/laravel-data-json-schemas

Transforms Spatie Data objects into JSON Schemas with built-in validation

1312.2k1](/packages/basillangevin-laravel-data-json-schemas)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
