PHPackages                             rabol/laravel-simple-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. [Utility &amp; Helpers](/categories/utility)
4. /
5. rabol/laravel-simple-subscription

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

rabol/laravel-simple-subscription
=================================

Simple subscription package for Laravel

v0.3.2(5y ago)3122MITPHPPHP ^7.4|^8.0

Since Feb 20Pushed 5y ago1 watchersCompare

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

READMEChangelog (5)Dependencies (8)Versions (6)Used By (0)

Simple subscription package for Laravel
=======================================

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

[![Latest Version on Packagist](https://camo.githubusercontent.com/68ad2887f554839c4e652e844dfa9f845a1c62ee08cec9e5f7d4e774b974d36f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7261626f6c2f6c61726176656c2d73696d706c652d737562736372697074696f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/rabol/laravel-simple-subscription)[![GitHub Tests Action Status](https://camo.githubusercontent.com/003caac5dd16e3042c75a43f6e8cc5dca17593683edc34c2a7f709feb838b98c/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f7261626f6c2f6c61726176656c2d73696d706c652d737562736372697074696f6e2f72756e2d74657374733f6c6162656c3d7465737473)](https://github.com/rabol/laravel-simple-subscription/actions?query=workflow%3ATests+branch%3Amaster)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/f02375a57927e67aa78bd26147a4251fe9004965ff702ceacb7f89f1c078617e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f7261626f6c2f6c61726176656c2d73696d706c652d737562736372697074696f6e2f436865636b253230262532306669782532307374796c696e673f6c6162656c3d636f64652532307374796c65)](https://github.com/rabol/laravel-simple-subscription/actions?query=workflow%3A%22Check+%26+fix+styling%22+branch%3Amaster)[![Total Downloads](https://camo.githubusercontent.com/33e145e1e24bfe5e5a793167aee137e9b6e8d777c760685086f17bc88ed34ca3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7261626f6c2f6c61726176656c2d73696d706c652d737562736372697074696f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/rabol/laravel-simple-subscription)

This is a simple to use subscription package for Laravel.

It is heavvly inspired by the renvex/laravel-subscriptions package, just simpler and working :)

Sorry, My point is that the renvex packages seems to be abandond.

Payments
--------

[](#payments)

- Payment support is in the works, so stay tuned.
- We will most likley use laraveldaily/laravel-invoices and then a payment package

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

[](#installation)

You can install the package via composer:

```
composer require rabol/laravel-simple-subscription
```

You can publish and run the migrations with:

```
php artisan vendor:publish --provider="Rabol\SimpleSubscription\SimpleSubscriptionServiceProvider" --tag="laravel-simple-subscription-migrations"
php artisan migrate
```

You can publish the config file with:

```
php artisan vendor:publish --provider="Rabol\SimpleSubscription\SimpleSubscriptionServiceProvider" --tag="laravel-simple-subscription-config"
```

This is the contents of the published config file:

```
return [
];
```

Usage
-----

[](#usage)

### Add Subscriptions to your model

[](#add-subscriptions-to-your-model)

For the sake of simplicity there is a trait that can be added to any model.

The most common use case is to add Subscription functionality to your User model just use the `Rabol\SimpleSubscription\Traits\HasSubscriptions` trait like this:

```
namespace App\Models;

use Rabol\SimpleSubscription\Traits\HasSubscriptions;
use Illuminate\Foundation\Auth\User as Authenticatable;

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

That's it, now you can use subscriptions on your user model only have to use that trait in our User model! Now your users may subscribe to plans.

Create a new Plan
-----------------

[](#create-a-new-plan)

```
$newPlan = SimpleSubscriptionPlan::create([
    'name' => 'My cool subscription',
    'description' => 'This is a very cool plan',
    'is_active' => true,
    'price' => 12.50,
    'signup_fee' => 0,
    'currency' => 'eur',
    'trial_period'  => 1,
    'trial_interval' => 'week',
    'invoice_period' => 1,
    'invoice_interval' => 'month',
    'grace_period' => 3,
    'grace_interval' => 'day',
]);
```

Add a feature

```
$planFeature = $newPlan
    ->features()
    ->create([
        'name' => 'My cool feature',
        'description' => 'This is my cool feature',
        'value' => 100,
        'resettable_period' => 2,
        'resettable_interval' => 'month',
        'sort_order' => 1,
    ]);
```

Subscription plan details
-------------------------

[](#subscription-plan-details)

```
$plan = SimpleSubscriptionPlan::find(1);
or
$plan = SimpleSubscriptionPlan::whereName('My cool subscription')->first();

// Get all plan features
$plan->features;

// Get all plan subscriptions
$plan->subscriptions;

// Check if the plan is free
$plan->isFree();

// Check if the plan has trial period
$plan->hasTrial();

// Check if the plan has grace period
$plan->hasGrace();
```

Get Feature Value
-----------------

[](#get-feature-value)

There are different ways to get information about a feature on a plan To get the value of the feature 'My cool feature'.:

```
// Use the plan instance to get feature's value
$myCoolFeatureValue = $plan->getFeatureByName('My Cool feature')->value;
```

Get feature usage
-----------------

[](#get-feature-usage)

```
// Get the usage of the feature you can
$myCoolFeatureUsage = SimpleSubscriptionPlanFeature::wherePlanId(1)->whereName('Feature 1')->first()->usage()->first()->used;
```

Create a Subscription
---------------------

[](#create-a-subscription)

You can subscribe a user to a plan by using the `newSubscription()` function available in the `HasSubscriptions` trait. First, retrieve an instance of your subscriber model, which typically will be your user model and an instance of the plan your user is subscribing to. Once you have retrieved the model instance, you may use the `newSubscription`method to create the model's subscription.

```
$user = User::find(1);
$plan = SimpleSubscriptionPlan::whereName('My cool subscription')->first();

$user->newSubscription($plan);
```

you can also specify the start date like this:

```
$user = User::find(1);
$plan = SimpleSubscriptionPlan::whereName('My cool subscription')->first();

$user->newSubscription($plan, Carbon::today());
```

If no start date is specified, the subscription will start today. The end date is calculated from the settings on the plan.

### Change the Plan

[](#change-the-plan)

To change the plan do this:

```
$newPlan = SimpleSubscriptionPlan::whereName('My second cool plan')->first();
$subscription = SimpleSubscriptionPlanSubscription::whereName('My cool subscription')->first();

// Change subscription plan
$subscription->changePlan($newPlan);
```

If both plans (current and new plan) have the same billing frequency (e.g., `invoice_period` and `invoice_interval`) the subscription will retain the same billing dates. If the plans don't have the same billing frequency, the subscription will have the new plan billing frequency, starting on the day of the change and *the subscription usage data will be cleared*. Also, if the new plan has a trial period, and it's a new subscription, the trial period will be applied.

### Subscription Feature Usage

[](#subscription-feature-usage)

There's multiple ways to determine the usage and ability of a particular feature in the user subscription, the most common one is `canUseFeature`:

The `canUseFeature` method returns `true` or `false` depending on multiple factors:

- Feature *is enabled*.
- Feature value isn't 0
- Or feature has remaining uses available.

```
$user->subscription('My cool subscription')->canUseFeature('My cool feature');
```

Other feature methods on the user subscription instance are:

- `getFeatureUsage`: returns how many times the user has used a particular feature.
- `getFeatureRemaining`: returns available uses for a particular feature.
- `getFeatureValue`: returns the feature value.

> All methods share the same signature: e.g. `$user->subscription('My cool subscription')->getFeatureUsage('My cool feature');`.

### Record Feature Usage

[](#record-feature-usage)

In order to effectively use the ability methods you will need to keep track of every usage of each feature (or at least those that require it). You may use the `recordFeatureUsage` method available through the user `subscription()` method:

```
$user->subscription('My cool subscription')->recordFeatureUsage('My cool feature');
```

The `recordFeatureUsage` method accept 3 parameters: the first one is the feature's name, the second one is the quantity of uses to add (default is `1`), and the third one indicates if the addition should be incremental (default behavior), when disabled the usage will be override by the quantity provided. E.g.:

```
// Increment by 2
$user->subscription('My cool subscription')->recordFeatureUsage('My cool feature', 2);

// Override with 9
$user->subscription('My cool subscription')->recordFeatureUsage('My cool feature', 9, false);
```

### Reduce Feature Usage

[](#reduce-feature-usage)

Reducing the feature usage is *almost* the same as incrementing it. Here we only *substract* a given quantity (default is `1`) to the actual usage: The difference from the `recordFeatureUsage` method is that the `reduceFeatureUsage` will not look at reset date

```
$user->subscription('My cool subscription')->reduceFeatureUsage('My cool feature', 2);
```

### Increase Feature Usage

[](#increase-feature-usage)

Increasing the feature usage is *almost* the same as `recordFeatureUsage`. this function simply *add* a given quantity to the value:

One more difference from the `recordFeatureUsage` method is that the `increaseFeatureUsage` will not look at reset date

```
$user->subscription('My cool subscription')->increaseFeatureUsage('My cool feature', 2);
```

### Clear The Subscription Usage Data

[](#clear-the-subscription-usage-data)

```
$user->subscription('My cool subscription')->usage()->delete();
```

### Check Subscription Status

[](#check-subscription-status)

For a subscription to be considered active *one of the following must be `true`*:

- Subscription has an active trial.
- Subscription `ends_at` is in the future.

```
$user->subscribedToPlanId($planId);
or
$user->subscribedToPlanName('My cool plan');
```

Alternatively you can use the following methods available in the subscription model:

```
$user->subscription('My cool subscription')->active();
$user->subscription('My cool subscription')->canceled();
$user->subscription('My cool subscription')->ended();
$user->subscription('My cool subscription')->onTrial();
```

> Canceled subscriptions with an active trial or `ends_at` in the future are considered active.

### Renew a Subscription

[](#renew-a-subscription)

To renew a subscription you may use the `renew` method available in the subscription model. This will set a new `ends_at` date based on the selected plan and *will clear the usage data* of the subscription.

```
$user->subscription('My cool subscription')->renew();
```

*Canceled subscriptions with an ended period can't be renewed.*

### Cancel a Subscription

[](#cancel-a-subscription)

To cancel a subscription, simply use the `cancel` method on the user's subscription:

```
$user->subscription('My cool subscription')->cancel();
```

By default the subscription will remain active until the end of the period, you may pass `true` to end the subscription *immediately*:

```
$user->subscription('My cool subscription')->cancel(true);
```

### Scopes

[](#scopes)

#### Subscription Model

[](#subscription-model)

```
// Get subscriptions by plan
$subscriptions = SimpleSubscriptionPlanSubscription::byPlanId($plan_id)->get();

// Get bookings of the given user
$user = \App\Models\User::find(1);
$bookingsOfUser = SimpleSubscriptionPlanSubscription::ofSubscriber($user)->get();

// Get subscriptions with trial ending in 3 days
$subscriptions = SimpleSubscriptionPlanSubscription::findEndingTrial(3)->get();

// Get subscriptions with ended trial
$subscriptions = SimpleSubscriptionPlanSubscription::findEndedTrial()->get();

// Get subscriptions with period ending in 3 days
$subscriptions = SimpleSubscriptionPlanSubscription::findEndingPeriod(3)->get();

// Get subscriptions with ended period
$subscriptions = SimpleSubscriptionPlanSubscription::findEndedPeriod()->get();
```

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

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

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

[](#contributing)

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

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

[](#security-vulnerabilities)

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

Credits
-------

[](#credits)

- [Steen Rabol](https://github.com/rabol)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community9

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

Every ~0 days

Total

5

Last Release

1901d ago

### Community

Maintainers

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

---

Top Contributors

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

---

Tags

rabollaravel-simple-subscription

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/rabol-laravel-simple-subscription/health.svg)

```
[![Health](https://phpackages.com/badges/rabol-laravel-simple-subscription/health.svg)](https://phpackages.com/packages/rabol-laravel-simple-subscription)
```

###  Alternatives

[guava/calendar

Adds support for vkurko/calendar to Filament PHP.

298241.0k3](/packages/guava-calendar)[tonysm/rich-text-laravel

Integrates Trix content with Laravel

46577.8k1](/packages/tonysm-rich-text-laravel)[hydrat/filament-table-layout-toggle

Filament plugin adding a toggle button to tables, allowing user to switch between Grid and Table layouts.

6292.3k1](/packages/hydrat-filament-table-layout-toggle)[tonysm/globalid-laravel

Identify app models with a URI. Inspired by the globalid gem.

45101.6k2](/packages/tonysm-globalid-laravel)[ralphjsmit/laravel-helpers

A package containing handy helpers for your Laravel-application.

13704.6k2](/packages/ralphjsmit-laravel-helpers)[spatie/laravel-screenshot

Take screenshots of web pages in Laravel apps

7615.9k2](/packages/spatie-laravel-screenshot)

PHPackages © 2026

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