PHPackages                             jgabboud/laravel-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. jgabboud/laravel-subscriptions

ActiveLibrary[Payment Processing](/categories/payments)

jgabboud/laravel-subscriptions
==============================

A Laravel package that will allow you to have dynamic subscriptions with free trials and discounts, enjoy!

314PHP

Since Sep 8Pushed 3y ago1 watchersCompare

[ Source](https://github.com/jgabboud/laravel-subscriptions)[ Packagist](https://packagist.org/packages/jgabboud/laravel-subscriptions)[ RSS](/packages/jgabboud-laravel-subscriptions/feed)WikiDiscussions master Synced 4w ago

READMEChangelogDependenciesVersions (1)Used By (0)

Laravel Subscriptions
=====================

[](#laravel-subscriptions)

A Laravel package that will allow you to have dynamic subscriptions with free trials and discounts with their respective middlewares, enjoy!

[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Total Downloads](https://camo.githubusercontent.com/0899e1b2817cec8b03dda105442259a23f48349e5bd6624e3692e97c07ec8511/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6a676162626f75642f6c61726176656c2d737562736372697074696f6e732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/jgabboud/laravel-subscriptions)

The library consists of 5 main tables:
plans
plan\_has\_items
plan\_items
plan\_subscriptions
plan\_subscription\_usages

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

[](#installation)

install the package using composer

```
composer require jgabboud/laravel-subscriptions

```

publish the vendor

```
php artisan vendor:publish --provider="Jgabboud\Subscriptions\SubscriptionServiceProvider"

```

Usage
-----

[](#usage)

First let's add the subscription out Model, supposedly the User Model

```
use Jgabboud\Subscriptions\Traits\HasSubscriptions;

class MyModel extends Model
{
    use HasSubscriptions;

    //...
}
```

*Now let's make use of our subscriptions!*

### Plan and Items

[](#plan-and-items)

In order to create a plan we will do the following:

```
$plan = Plan::create([
    'name' => 'Gold Plan',
    'description' => 'This plan is the one for you',
    'price' => 25.50,
    'currency' => 'USD',
    'trial_duration' => 20,
    'trial_duration_type' => 'days',
    'package_duration' => 1,
    'package_duration_type' => 'month',
    'subscriptions_limit' => 1500
]);

//-- check if plan is active
$plan->isActive();

//-- activate plan
$plan->activate();

//-- deactivate plan
$plan->deactivate();
```

notice the duration type, whether *trial\_duration\_type* or *package\_duration\_type*, can be `days` ` month` or `year`

> to create a free plan just set the price to 0.

To check whether the plan is free just hit:

```
$plan = Plan::find(1);
$plan->isFree();
```

To assign an item to a plan first lets create the item and then assign it as follows:

```
//-- create plan item
PlanItem::create([
     'name' => 'Emails',
     'description' => 'Limit number of emails'
]);

$plan = Plan::find(1);
$items[] = (object)['item_id' => 1, 'value' => 15,'item_duration' => 10, 'item_duration_type' => 'days'];
$items[] = (object)['item_id' => 2, 'value' => 30,'item_duration' => 10, 'item_duration_type' => 'days'];

//-- assign items to plan
$plan->assignItems($items);

item_ids = [1, 2];
//-- remove items from plan
$plan->revokeItems($item_ids);
```

### Subscribers

[](#subscribers)

In order to subscribe a User Model to a plan:

```
$plan = Plan::find(1);
$user = User::find(1);

//-- subscribe user to plan
$user->subscribe($plan);

//-- get user subscriptions
$user->planSubscriptions
```

Structure
---------

[](#structure)

The plan table will hold the the details of each plan regarding the name description, prices, trial periods and more. Now a plan might have many items inside it e.g maximum number of products you can create using this subscription. Hence we will use the plan\_items table to initialize these items. Since a plan can have more than one item and an item can belong to more than one plan we connect these two using the plan\_has\_items.

Now for a user to subscribe to plan we will mimic the plans details to the plan\_subscriptions table with the corresponding subscriber info and plan info, and we will mimic the items to the plan\_subscription\_usages. The main reason for mimic-ing nearly most of the data, beside keeping track of the plans that a user has subscribed to, is to keep track of what the plan was really like when the user subscribed at that day, since the same plan might be updated later on and the newly updated plan should **not** take effect on the what the users has really subscribed for back then, but should take effect as of new subscriptions.

Free Trials
-----------

[](#free-trials)

you can create a package, name it "30 days Free Trial", give it 30 days trial duration and the package duration will be 0. In this you have a created a free trial for the users. on the other hand you can as well give an ongoing subscription a free trial by adding the free trial duration to it along with the package duration.

what really happens in the plan\_subscriptions table is that the record for each subscription will be inserted only once with the corresponding subscriber. and now every time the subscription renews we only update the starts\_at and ends\_at fields. and we can either reset the plan subscription usages to what it became in the new plan, or role over the old usages to the new depending on the business. what if we want to keep track of the history of subscription? you can later create an invoice table that will hold the details of each subscription.

One can always cancel a subscription

Addons and Bundles
------------------

[](#addons-and-bundles)

you can later add add another table that will have more than one item in it and a user can buy that bundle and, similarly, append the items to plan\_subscription\_usages with an addon flag

Pay as You Go
-------------

[](#pay-as-you-go)

by default the subscriptions library has no limitations on how many times the items should be used and thus you can specify a functionality that will calculate how many time the item has been used a set a billing price for it.

###  Health Score

16

—

LowBetter than 5% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity24

Early-stage or recently created project

 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/e68cd9c16518a36ee5403456262c2c8e06ee2937da2c549898b99a868980c7cb?d=identicon)[jgabboud](/maintainers/jgabboud)

---

Top Contributors

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

### Embed Badge

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

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

###  Alternatives

[omnipay/paypal

PayPal gateway for Omnipay payment processing library

3156.8M53](/packages/omnipay-paypal)[eduardokum/laravel-boleto

Biblioteca com boletos para o laravel

626351.9k2](/packages/eduardokum-laravel-boleto)[tbbc/money-bundle

This is a Symfony bundle that integrates moneyphp/money library (Fowler pattern): https://github.com/moneyphp/money.

1961.9M](/packages/tbbc-money-bundle)[2checkout/2checkout-php

2Checkout PHP Library

83740.3k2](/packages/2checkout-2checkout-php)[smhg/sepa-qr-data

Generate QR code data for SEPA payments

61717.2k5](/packages/smhg-sepa-qr-data)[omnipay/dummy

Dummy driver for the Omnipay payment processing library

271.2M33](/packages/omnipay-dummy)

PHPackages © 2026

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