PHPackages                             aldeebhasan/la-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. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. aldeebhasan/la-subscription

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

aldeebhasan/la-subscription
===========================

this package will take your hand in your project to handle users subscription

1.1.0(1y ago)557MITPHPPHP ^8.2

Since Nov 9Pushed 1y ago1 watchersCompare

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

READMEChangelog (3)Dependencies (9)Versions (5)Used By (0)

LA SUBSCRIPTION
================

[](#la-subscription-)

[![Latest Version on Packagist](https://camo.githubusercontent.com/8d6b80aea921f5a981fb2d99d16cd22abf0fb2fc689ee25c179c4844056d2c08/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f616c64656562686173616e2f6c612d737562736372697074696f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/aldeebhasan/la-subscription)[![GitHub Tests Action Status](https://camo.githubusercontent.com/6191111350ea4174e0992a6db445af97f840e09aec530f0c5354072356109a63/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f616c64656562686173616e2f6c612d737562736372697074696f6e2f72756e2d74657374732e796d6c3f6272616e63683d6d6173746572266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/aldeebhasan/la-subscription/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/b9edbd2fad6108815d677f0640a14cd814b684b91aad6a1d8daa51ca6c9fdeb0/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f616c64656562686173616e2f6c612d737562736372697074696f6e2f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d6173746572266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/aldeebhasan/la-subscription/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Codacy Badge](https://camo.githubusercontent.com/878ccea15c049565a69f1e2b69d29893fcdcbbc375beaf589cc34ff526ada5fe/68747470733a2f2f6170702e636f646163792e636f6d2f70726f6a6563742f62616467652f47726164652f3136386534376535363639633466396461356630613963633466353662323934)](https://app.codacy.com/gh/aldeebhasan/la-subscription/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade)[![Total Downloads](https://camo.githubusercontent.com/b214777da515fe4c9a4b22ffba4b93db9863be3c2cdd868ad7a176b04f55fab6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f616c64656562686173616e2f6c612d737562736372697074696f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/aldeebhasan/la-subscription)

About
-----

[](#about)

LA SUBSCRIPTION is a robust package designed to simplify the implementation and management of subscription-based services within Laravel applications. It provides a flexible approach to handle various subscription plans, making it ideal for SaaS applications, membership sites, and any system requiring recurring billing.

[![](/art/screenshot.jpg)](/art/screenshot.jpg)

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

[](#installation)

You can install the package via composer:

```
composer require aldeebhasan/la-subscription
```

You can publish and run the migrations with:

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

You can publish the config file with:

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

This is the contents of the published config file:

```
return [
    'prefix' => env("LA_SUBSCRIPTION_PREFIX", "la"),
    'grace_period' => env("LA_GRACE_PERIOD", 7),
    'path' => env("LA_PATH", 'la-subscriptions'),
    'middleware' => ['web'],
];
```

Optionally, you can publish the views using

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

Tip

As soon as you install this package, you can access the package dashboard through the path initialized in the configuration file.

By default it is `http://*/la-subscriptions`. If you are working on the local environment, it will be `http://127.0.0.1:8000/la-subscriptions/dashboard`

Usage
-----

[](#usage)

To start using this package you need first to add `HasSubscription` Trait to the model you want to handle the subscription for it.

```
namespace App\Models;

use Aldeebhasan\LaSubscription\Traits\HasSubscription;
use Illuminate\Database\Eloquent\Model;

class User extends Model
{
    use HasSubscriptions;
}
```

Setup Features
--------------

[](#setup-features)

The basic unit of any subscription is the features, you can group them under specific groups according to there type.

You can create features either using the `package dashboard` or `manually` as follow:

```
namespace Database\Seeders;

use Illuminate\Database\Seeder;
use Aldeebhasan\LaSubscription\Models\Feature;
use  Aldeebhasan\LaSubscription\Models\Group;
use Aldeebhasan\LaSubscription\Enums\GroupTypeEnum;

class FeatureSeeder extends Seeder
{
    public function run()
    {
        $group = Group::create([
        'name' => "Sales",
        'type' => GroupTypeEnum::FEATURE
        ]);

        $feature_1 = Feature::create([
            'limited'     => false,
            'name'        => 'Invoice Managements',
            'code'        => 'invoices',
            'group_id'    => $group->id,
        ]);

        $feature_2 = Feature::create([
            'limited'     => true,
            'name'        => 'User Managements',
            'code'        => 'users',
            'group_id'    => $group->id,
        ]);
    }
}
```

The features can be limited/unlimited. The limited feature has specific quota need to be specified, and the subnscriber can't use more that the specified quota. On the other hand, the unlimited feature has unlimited number of usage quota. This can be identified using the `limited` param.

Setup Plans
-----------

[](#setup-plans)

Plans work like a group of features that will be available to the subscriber. You can define a new plan either using the `package dashboard` or `manually` as follow:

```
namespace Database\Seeders;

use Illuminate\Database\Seeder;
use Aldeebhasan\LaSubscription\Enums\BillingCycleEnum;
use Aldeebhasan\LaSubscription\Models\Feature;
use Aldeebhasan\LaSubscription\Models\Product;
use Aldeebhasan\LaSubscription\Models\Group;
use Aldeebhasan\LaSubscription\Enums\GroupTypeEnum;

class PlanSeeder extends Seeder
{
    public function run()
    {
        $group = Group::create([
        'name' => "Premium Plans",
        'type' => GroupTypeEnum::PLAN
        ]);

        $plan = Product::create([
            'name'         => "Starter",
            'description'  => 'Description of starter plan',
            'code'         => 'starter',
            'group_id'     => $group->id,
            'price'        => 15,
            'price_yearly' => 12,
        ]);

        $feature_1 = Feature::whereCode('users')->first();
        $feature_2 = Feature::whereCode('users')->first();
        $plan->features()->attach($feature_1, ['value' => 20]);
        $plan->features()->attach($feature_2);
    }
}
```

Handle Subscriptions
--------------------

[](#handle-subscriptions)

Now everything is ready to create a new subscription for the subscribing model :

### New Subscription

[](#new-subscription)

```
$subscriber = User::create(['name'=>'Subscriber']);
$plan = \Aldeebhasan\LaSubscription\Models\Product::firstWhere('code','starter');

\Aldeebhasan\LaSubscription\LaSubscription::make($subscriber)->subscribeTo($plan)
//OR
\Aldeebhasan\LaSubscription\LaSubscription::make($subscriber)->subscribeTo($plan, now()->endOfMonth())
//OR
$period = 12; // in months
\Aldeebhasan\LaSubscription\LaSubscription::make($subscriber)->subscribeTo($plan, now()->endOfMonth(), $period)
```

### Switch Plan

[](#switch--plan)

If you already subscribed to a plan you want to change the subscription plan to another one (like upgrade the subscription), you can use `switchTo`. Note that you can switch the plan at a specific time in the future and with different billing cycle.

```
$newPlan = \Aldeebhasan\LaSubscription\Models\Product::firstWhere('code','silver');

\Aldeebhasan\LaSubscription\LaSubscription::make($subscriber)->switchTo($newPlan)
//OR
\Aldeebhasan\LaSubscription\LaSubscription::make($subscriber)->switchTo($newPlan, now()->endOfMonth())
//OR
$period = 6; // in months
\Aldeebhasan\LaSubscription\LaSubscription::make($subscriber)->switchTo($plan, now()->endOfMonth(), $period)
```

Note

By switching subscription , the old subscription will be set at suppressed status, and the suppressed date will be stored.

Note

The `switchTo` function has an optional parameter named as `$withPlugins`. This param indicate if you want to install the current installed plugins with the switched plan or not. "we will talk about the Plugins later"

### Renew Subscription

[](#renew-subscription)

In case you want to renew the current subscription you can do it as follow:

```
$period = 6; // in months
\Aldeebhasan\LaSubscription\LaSubscription::make($subscriber)->renew($period)
```

Note

The `renew` function has an optional parameter named as `$withPlugins`. This param indicate if you want to renew the plugins with the plan or not. "we will talk about the Plugins later"

### Unlimited Subscription

[](#unlimited-subscription)

At any point of time, if you want to bypass all the subscription features check for specific subscriber, you can enable `Unlimited access` for him. The will enable him to access to all the features with out any limitations.

```
$period = 6; // in months
\Aldeebhasan\LaSubscription\LaSubscription::make($subscriber)->setUnlimitedAccess(true)
// OR
$subscriber->setUnlimitedAccess(true)
```

### Cancel/Resume Subscription

[](#cancelresume-subscription)

At any point of time, if you want to cancel the user subscription or resumed canceled one, you can do it as follow:

```
\Aldeebhasan\LaSubscription\LaSubscription::make($subscriber)->cancel()
// OR
\Aldeebhasan\LaSubscription\LaSubscription::make($subscriber)->cancel(now()->endOfMonth())

//To resume
\Aldeebhasan\LaSubscription\LaSubscription::make($subscriber)->resume()
```

Setup Plugins
-------------

[](#setup-plugins)

Plugins in this package represent a set of figures that can be added to the subscription along with the plan. As example, the user at the starter plan may want to enable a plugin that give him access to specific features that are not enabled in his plan. Plugins can be considered as a small plans with limited set of features.

Plugins can be RECURRING/NON\_RECURRING,

- The RECURRING plugin will follow the same subscription billing cycle, if not renewed, the subscriber will loss the access to its features.
- The NON\_RECURRING plugins will be enabled forever, there is no need to renew it at all.

You can define new plugins either using the `package dashboard` or `manually` as follow:

```
$group = Group::create([
'name' => "Accounting Plugins",
'type' => GroupTypeEnum::PLUGIN
]);

$plugin = Product::create([
    'name'         => "Advanced reports",
    'description'  => 'Description of Advanced reports',
    'code'         => 'advanced-reports',
    'group_id'     => $group->id,
    'type'         => BillingCycleEnum::RECURRING, // Or Un-Recurring
    'price'        => 15;
    'price_yearly' => 12;
]);

\Aldeebhasan\LaSubscription\LaSubscription::make($subscriber)->addPlugin($plugin);
//OR as specific time
\Aldeebhasan\LaSubscription\LaSubscription::make($subscriber)->addPlugin($plugin, now()->endOfMonth());
//OR you can specify the model that caused this addition (ex: the Invoice item or a manager user), by default it will be the subscriber himself.
\Aldeebhasan\LaSubscription\LaSubscription::make($subscriber)->addPlugin($plugin, now()->endOfMonth(), $manager);
```

At any point of time you can cancel any plugin or resume it as follow:

```
$causative = $subscriber->manager; // optional
\Aldeebhasan\LaSubscription\LaSubscription::make($subscriber)->cancelPlugin($plugin , $causative)
//To resume
\Aldeebhasan\LaSubscription\LaSubscription::make($subscriber)->resumePlugin($plugin , $causative)
```

Warning

When a plugin is cancelled, it will not be renewed with the plan any more.

Features availability
---------------------

[](#features-availability)

You can check if the subscriber can consume feature/features as follow:

```
$code = "feature-code" // or  ["feature-1-code" ,"feature-2-code" ]
$subscriber->canConsume($code );
```

You can check if the subscriber can consume any feature/features as follow:

```
$code = ["feature-1-code" ,"feature-2-code" ]
$subscriber->canConsumeAny($code);
```

For the features that has limited quotas, you can register the consumption of that feature as follow

```
$code = 'feature-code';
$amount = 1; // 1 is the default value
$subscriber->consume($code, $amount);
```

For any reason that require you to return the consumption value to the subscriber you can do that with the follow:

```
$code = 'feature-code';
$amount = 1; // 1 is the default value
$subscriber->retrieve($code, $amount);
```

To retrieve the current consumption of specific feature

```
$subscriber->getCurrentConsumption('feature-code');
```

To retrieve the remaining balance of limited features

```
$subscriber->getBalance('feature-code');
```

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

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

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

[](#security-vulnerabilities)

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

Credits
-------

[](#credits)

- [Hasan Deeb](https://github.com/aldeebhasan)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance38

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity54

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

Every ~7 days

Total

3

Last Release

534d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/74e7b9d93b0f666f462ad0be43dde05991e9d141f9fe840009775808107d440e?d=identicon)[aldeebhasan](/maintainers/aldeebhasan)

---

Top Contributors

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

---

Tags

laravelsubscribersubscriptionslaravelaldeebhasanla-subscription

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/aldeebhasan-la-subscription/health.svg)

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

###  Alternatives

[spatie/laravel-permission

Permission handling for Laravel 12 and up

12.9k89.8M1.0k](/packages/spatie-laravel-permission)[bezhansalleh/filament-shield

Filament support for `spatie/laravel-permission`.

2.8k2.9M88](/packages/bezhansalleh-filament-shield)[php-open-source-saver/jwt-auth

JSON Web Token Authentication for Laravel and Lumen

8359.8M53](/packages/php-open-source-saver-jwt-auth)[spatie/laravel-login-link

Quickly login to your local environment

4381.2M1](/packages/spatie-laravel-login-link)[ryangjchandler/laravel-cloudflare-turnstile

A simple package to help integrate Cloudflare Turnstile.

438896.6k2](/packages/ryangjchandler-laravel-cloudflare-turnstile)[spatie/laravel-passkeys

Use passkeys in your Laravel app

444494.4k16](/packages/spatie-laravel-passkeys)

PHPackages © 2026

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