PHPackages                             hoceineel/laravel-modular-subscriptions - 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. [Payment Processing](/categories/payments)
4. /
5. hoceineel/laravel-modular-subscriptions

ActiveLibrary[Payment Processing](/categories/payments)

hoceineel/laravel-modular-subscriptions
=======================================

A flexible Laravel package for managing subscriptions with custom modules

v1.0.0(1y ago)18MITPHPPHP ^8.2

Since Oct 17Pushed 1y ago1 watchersCompare

[ Source](https://github.com/HoceineEl/laravel-modular-subscriptions)[ Packagist](https://packagist.org/packages/hoceineel/laravel-modular-subscriptions)[ RSS](/packages/hoceineel-laravel-modular-subscriptions/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (3)Versions (2)Used By (0)

Laravel Modular Subscriptions
=============================

[](#laravel-modular-subscriptions)

A flexible and customizable package for managing subscriptions with modular features in Laravel applications.

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

[](#installation)

1. Install the package via Composer:

```
composer require hoceineel/laravel-modular-subscriptions
```

2. Publish the configuration file:

```
php artisan vendor:publish --provider="HoceineEl\LaravelModularSubscriptions\ModularSubscriptionsServiceProvider" --tag="config"
```

3. Publish the migrations:

```
php artisan vendor:publish --provider="HoceineEl\LaravelModularSubscriptions\ModularSubscriptionsServiceProvider" --tag="migrations"
```

4. Run the migrations:

```
php artisan migrate
```

Configuration
-------------

[](#configuration)

After publishing the configuration file, you can find it at `config/modular-subscriptions.php`. Here you can customize the model classes used by the package and define default modules if needed.

```
return [
    'modules' => [
        // Add your default modules here
    ],
    'models' => [
        'plan' => HoceineEl\LaravelModularSubscriptions\Models\Plan::class,
        'subscription' => HoceineEl\LaravelModularSubscriptions\Models\Subscription::class,
        'module' => HoceineEl\LaravelModularSubscriptions\Models\Module::class,
        'usage' => HoceineEl\LaravelModularSubscriptions\Models\ModuleUsage::class,
    ],
];
```

Usage
-----

[](#usage)

### Creating a Module

[](#creating-a-module)

Create a new module by extending the `BaseModule` class:

```
use HoceineEl\LaravelModularSubscriptions\Modules\BaseModule;
use HoceineEl\LaravelModularSubscriptions\Models\Subscription;

class SubscribersModule extends BaseModule
{
    public function getName(): string
    {
        return 'subscribers';
    }

    public function getLabelKey(): string
    {
        return 'Subscribers'; // we will use it like __('Subscribers')
    }

    public function calculateUsage(Subscription $subscription): int
    {
        return $subscription->subscribable->subscribers()->count();
    }

    public function getPricing(Subscription $subscription): float
    {
        $subscriberCount = $this->calculateUsage($subscription);
        return $subscriberCount * 0.5; // $0.50 per subscriber
    }

    public function canUse(Subscription $subscription): bool
    {
        $usage = $this->calculateUsage($subscription);
        $limit = 1000; // Example limit
        return $usage < $limit;
    }
}
```

### Using the Subscribable Trait

[](#using-the-subscribable-trait)

Add the `Subscribable` trait to your model:

```
use HoceineEl\LaravelModularSubscriptions\Traits\Subscribable;

class User extends Model
{
    use Subscribable;
    // ...
}
```

### Managing Subscriptions

[](#managing-subscriptions)

Create a new subscription:

```
$user->newSubscription($planId, $trialDays);
```

Check subscription status:

```
if ($user->hasSubscription()) {
    // User has an active subscription
}

if ($user->onTrial()) {
    // User is on trial
}

$daysLeft = $user->daysLeft();
```

Cancel a subscription:

```
$user->cancel();
```

Renew a subscription:

```
$user->renew(30); // Renew for 30 days
```

Change subscription plan:

```
$user->changePlan($newPlanId);
```

### Managing Module Usage

[](#managing-module-usage)

Record module usage:

```
$user->recordUsage('subscribers', 5);
```

Check if a module can be used:

```
if ($user->canUseModule('subscribers')) {
    // User can use the subscribers module
}
```

Advanced Usage
--------------

[](#advanced-usage)

### Extending Trial Periods

[](#extending-trial-periods)

```
$user->extendTrial(7); // Extend trial by 7 days
```

### Ending Trial Periods

[](#ending-trial-periods)

```
$user->endTrial();
```

### Calculating Total Usage and Pricing

[](#calculating-total-usage-and-pricing)

```
use HoceineEl\LaravelModularSubscriptions\Facades\ModularSubscriptions;

$subscription = $user->activeSubscription();
$totalUsage = ModularSubscriptions::totalUsage($subscription);
$totalPricing = ModularSubscriptions::totalPricing($subscription);
```

Extending the Package
---------------------

[](#extending-the-package)

You can extend the functionality of this package by:

1. Creating custom modules for specific features
2. Extending the base models (Plan, Subscription, Module, ModuleUsage)

Testing
-------

[](#testing)

Run the tests with:

```
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
--------

[](#security)

If you discover any security-related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Hoceine El Idrissi](https://github.com/hoceineel)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

---

Made with ❤️ by [Hoceine El Idrissi](https://github.com/hoceineel)

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance37

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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

Unknown

Total

1

Last Release

572d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/04ce90a561972b33397a9285fd25637831e1a0542e916281551b860bdcdf45e6?d=identicon)[HoceineEl](/maintainers/HoceineEl)

---

Top Contributors

[![HoceineEl](https://avatars.githubusercontent.com/u/126410988?v=4)](https://github.com/HoceineEl "HoceineEl (4 commits)")

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/hoceineel-laravel-modular-subscriptions/health.svg)

```
[![Health](https://phpackages.com/badges/hoceineel-laravel-modular-subscriptions/health.svg)](https://phpackages.com/packages/hoceineel-laravel-modular-subscriptions)
```

###  Alternatives

[lemonsqueezy/laravel

A package to easily integrate your Laravel application with Lemon Squeezy.

58596.1k](/packages/lemonsqueezy-laravel)[ssheduardo/redsys-laravel

Package redsys for laravel

100129.5k1](/packages/ssheduardo-redsys-laravel)[duncanmcclean/simple-commerce

A simple, yet powerful e-commerce addon for Statamic.

16313.2k2](/packages/duncanmcclean-simple-commerce)[tsaiyihua/laravel-ecpay

ecpay library for laravel

6416.3k](/packages/tsaiyihua-laravel-ecpay)[alifaraun/laravel-moamalat-pay

Easy - Moamalat Lightbox integration for Laravel.

1914.0k](/packages/alifaraun-laravel-moamalat-pay)[duncanmcclean/statamic-cargo

Comprehensive e-commerce addon for Statamic. Build bespoke e-commerce sites without the complexity.

322.8k](/packages/duncanmcclean-statamic-cargo)

PHPackages © 2026

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