PHPackages                             wakjoko/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. [Database &amp; ORM](/categories/database)
4. /
5. wakjoko/laravel-subscriptions

ActiveLibrary[Database &amp; ORM](/categories/database)

wakjoko/laravel-subscriptions
=============================

Fork of rinvex/laravel-subscriptions without dependency on users table. You can attach subscription into any model.

v5.0.1(5y ago)014MITPHPPHP ^7.4.0 || ^8.0.0

Since Jun 29Pushed 5y agoCompare

[ Source](https://github.com/wakjoko/laravel-subscriptions)[ Packagist](https://packagist.org/packages/wakjoko/laravel-subscriptions)[ Docs](https://rinvex.com)[ RSS](/packages/wakjoko-laravel-subscriptions/feed)WikiDiscussions master Synced yesterday

READMEChangelog (1)Dependencies (10)Versions (26)Used By (0)

Wakjoko Subscriptions
=====================

[](#wakjoko-subscriptions)

**Wakjoko Subscriptions** is a fork version of rinvex/laravel-subscriptions without dependency of users table. You can attach subscriptions into any model.

Considerations
--------------

[](#considerations)

- Payments are out of scope for this package.
- You may want to extend some of the core models, in case you need to override the logic behind some helper methods like `renew()`, `cancel()` etc. E.g.: when cancelling a subscription you may want to also cancel the recurring payment attached.

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

[](#installation)

1. Install the package via composer:

    ```
    composer require wakjoko/laravel-subscriptions
    ```
2. Publish resources (migrations and config files):

    ```
    php artisan wakjoko:publish:subscriptions
    ```
3. Execute migrations via the following command:

    ```
    php artisan wakjoko:migrate:subscriptions
    ```
4. Done!

Usage
-----

[](#usage)

### Add Subscriptions to User model

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

**Wakjoko Subscriptions** has been specially made for Eloquent and simplicity has been taken very serious as in any other Laravel related aspect. To add Subscription functionality to your User model just use the `\Wakjoko\Subscriptions\Traits\HasSubscriptions` trait like this:

```
namespace App\Models;

use Wakjoko\Subscriptions\Traits\HasSubscriptions;
use Illuminate\Foundation\Auth\User as Authenticatable;

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

That's it, we only have to use that trait in our User model! Now your users may subscribe to plans.

### Create a Plan

[](#create-a-plan)

```
$plan = app('wakjoko.subscriptions.plan')->create([
    'name' => 'Pro',
    'description' => 'Pro plan',
    'price' => 9.99,
    'signup_fee' => 1.99,
    'invoice_period' => 1,
    'invoice_interval' => 'month',
    'trial_period' => 15,
    'trial_interval' => 'day',
    'sort_order' => 1,
    'currency' => 'USD',
]);

// Create multiple plan features at once
$plan->features()->saveMany([
    new PlanFeature(['name' => 'listings', 'value' => 50, 'sort_order' => 1]),
    new PlanFeature(['name' => 'pictures_per_listing', 'value' => 10, 'sort_order' => 5]),
    new PlanFeature(['name' => 'listing_duration_days', 'value' => 30, 'sort_order' => 10, 'resettable_period' => 1, 'resettable_interval' => 'month']),
    new PlanFeature(['name' => 'listing_title_bold', 'value' => 'Y', 'sort_order' => 15])
]);
```

### Get Plan Details

[](#get-plan-details)

You can query the plan for further details, using the intuitive API as follows:

```
$plan = app('wakjoko.subscriptions.plan')->find(1);

// 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();
```

Both `$plan->features` and `$plan->subscriptions` are collections, driven from relationships, and thus you can query these relations as any normal Eloquent relationship. E.g. `$plan->features()->where('name', 'listing_title_bold')->first()`.

### Get Feature Value

[](#get-feature-value)

Say you want to show the value of the feature *pictures\_per\_listing* from above. You can do so in many ways:

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

// Query the feature itself directly
$amountOfPictures = app('wakjoko.subscriptions.plan_feature')->where('name', 'pictures_per_listing')->first()->value;

// Get feature value through the subscription instance
$amountOfPictures = app('wakjoko.subscriptions.plan_subscription')->find(1)->getFeatureValue('pictures_per_listing');
```

### Create a Subscription

[](#create-a-subscription)

You can subscribe a subscribable 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 subscribable model and an instance of the plan your subscribable is subscribing to. Once you have retrieved the model instance, you may use the `newSubscription` method to create the model's subscription.

```
$subscribable = User::find(1);
$plan = app('wakjoko.subscriptions.plan')->find(1);

$subscribable->newSubscription('main', $plan);
```

The first argument passed to `newSubscription` method should be the title of the subscription. If your application offer a single subscription, you might call this `main` or `primary`. The second argument is the plan instance your subscribable is subscribing to.

### Change the Plan

[](#change-the-plan)

You can change subscription plan easily as follows:

```
$plan = app('wakjoko.subscriptions.plan')->find(2);
$subscription = app('wakjoko.subscriptions.plan_subscription')->find(1);

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

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.

### Feature Options

[](#feature-options)

Plan features are great for fine tuning subscriptions, you can topup certain feature for X times of usage, so users may then use it only for that amount. Features also have the ability to be resettable and then it's usage could be expired too. See the following examples:

```
// Find plan feature
$feature = app('wakjoko.subscriptions.plan_feature')->where('name', 'listing_duration_days')->first();

// Get feature reset date
$feature->getResetDate(new \Carbon\Carbon());
```

### Subscription Feature Usage

[](#subscription-feature-usage)

There's multiple ways to determine the usage and ability of a particular feature in the subscribable 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`/`false`/`NULL`.
- Or feature has remaining uses available.

```
$subscribable->subscription('main')->canUseFeature('listings');
```

Other feature methods on the subscribable subscription instnace are:

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

> All methods share the same signature: e.g. `$subscribable->subscription('main')->getFeatureUsage('listings');`.

### 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 subscribable `subscription()` method:

```
$subscribable->subscription('main')->recordFeatureUsage('listings');
```

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
$subscribable->subscription('main')->recordFeatureUsage('listings', 2);

// Override with 9
$subscribable->subscription('main')->recordFeatureUsage('listings', 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:

```
$subscribable->subscription('main')->reduceFeatureUsage('listings', 2);
```

### Clear The Subscription Usage Data

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

```
$subscribable->subscription('main')->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.

```
$subscribable->subscribedTo($planId);
```

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

```
$subscribable->subscription('main')->active();
$subscribable->subscription('main')->canceled();
$subscribable->subscription('main')->ended();
$subscribable->subscription('main')->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.

```
$subscribable->subscription('main')->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 subscribable's subscription:

```
$subscribable->subscription('main')->cancel();
```

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

```
$subscribable->subscription('main')->cancel(true);
```

### Scopes

[](#scopes)

#### Subscription Model

[](#subscription-model)

```
// Get subscriptions by plan
$subscriptions = app('wakjoko.subscriptions.plan_subscription')->byPlanId($plan_id)->get();

// Get subscriptions with trial ending in 3 days
$subscriptions = app('wakjoko.subscriptions.plan_subscription')->findEndingTrial(3)->get();

// Get subscriptions with ended trial
$subscriptions = app('wakjoko.subscriptions.plan_subscription')->findEndedTrial()->get();

// Get subscriptions with period ending in 3 days
$subscriptions = app('wakjoko.subscriptions.plan_subscription')->findEndingPeriod(3)->get();

// Get subscriptions with ended period
$subscriptions = app('wakjoko.subscriptions.plan_subscription')->findEndedPeriod()->get();
```

### Models

[](#models)

**Wakjoko Subscriptions** uses 4 models:

```
Wakjoko\Subscriptions\Models\Plan;
Wakjoko\Subscriptions\Models\PlanFeature;
Wakjoko\Subscriptions\Models\PlanSubscription;
Wakjoko\Subscriptions\Models\PlanSubscriptionUsage;
```

Changelog
---------

[](#changelog)

Refer to the [Changelog](CHANGELOG.md) for a full history of the project.

License
-------

[](#license)

This software is released under [The MIT License (MIT)](LICENSE).

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity78

Established project with proven stability

 Bus Factor1

Top contributor holds 98.1% 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 ~55 days

Total

24

Last Release

1959d ago

Major Versions

v0.0.4 → v1.0.02018-10-05

v1.0.2 → v2.0.02019-03-03

v2.1.1 → v3.0.02019-09-22

v3.0.2 → v4.0.02020-03-15

v4.1.0 → v5.0.02020-12-22

PHP version history (5 changes)v0.0.1PHP ^7.0.0

v0.0.3PHP ^7.1.3

v2.0.0PHP ^7.2.0

v4.0.0PHP ^7.4.0

v5.0.1PHP ^7.4.0 || ^8.0.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/26d99fbe4404013c5f3f858859bc1517cb0911afc643df1de193b3ca0734859d?d=identicon)[wakjoko](/maintainers/wakjoko)

---

Top Contributors

[![Omranic](https://avatars.githubusercontent.com/u/406705?v=4)](https://github.com/Omranic "Omranic (252 commits)")[![wakjoko](https://avatars.githubusercontent.com/u/8953339?v=4)](https://github.com/wakjoko "wakjoko (4 commits)")[![ppalmeida](https://avatars.githubusercontent.com/u/197936?v=4)](https://github.com/ppalmeida "ppalmeida (1 commits)")

---

Tags

laraveldatabasefeaturerecurringsubscriptionplanvalue

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[laravelcm/laravel-subscriptions

Laravel Subscriptions is a flexible plans and subscription management system for Laravel, with the required tools to run your SAAS like services efficiently. It's simple architecture, accompanied by powerful underlying to afford solid platform for your business.

23255.0k3](/packages/laravelcm-laravel-subscriptions)

PHPackages © 2026

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