lacodix/laravel-plans
Laravel package to manage SaaS plans, addons, subscriptions, and optional features. Supports countable/uncountable features with limits, resets, and consumption across plans, plus translations, ordering, and metadata—billing/invoicing not included.
You can find the entire documentation for this package on our documentation site. Including several usecases with detailed explanation.
composer require lacodix/laravel-plans
To get familiar with all settings and possibilities, please see the more detailed examples. This is only a very quick overview how the package can work.
Add our HasSubscription Trait to any model.
use Lacodix\LaravelPlans\Models\Traits\HasSubscriptions;
class User extends Authenticatable {
use HasSubscriptions;
...
}
Create a Plan with Features (the latter is optional, if you don't need feature functionality).
use Lacodix\LaravelPlans\Enums\Interval;
use Lacodix\LaravelPlans\Models\Feature;
use Lacodix\LaravelPlans\Models\Plan;
$myPlan = Plan::create([
'slug' => 'my-plan',
'name' => 'My Plan', // can also be locale-array - see Feature below
'price' => 50.0,
'active' => true,
'billing_interval' => Interval::MONTH,
'billing_period' => 1,
'meta' => [
'price_per_token' => 0.05,
],
]);
$myFeature = Feature::create([
'slug' => 'tokens',
'name' => [
'de' => 'Zusätzliche Tokens',
'en' => 'Additional Tokens',
],
]);
$myPlan->features()->attach($myFeature, [
'value' => 1000,
'resettable_period' => 1,
'resettable_interval' => Interval::MONTH,
]);
// Subscribe to multiple plans
$user->subscribe($myPlan1, 'main');
$user->subscribe($myPlan2, 'addon');
// Change Subscription
$user->subscribe($myPlan3, 'main'); // will replace myPlan1 subscription
// Renew
$user->subscriptions()->first()->renew();
// Cancel
$user->subscriptions()->first()->cancel();
composer test
Please run the following commands and solve potential problems before committing and think about adding tests for new functionality.
composer rector:test
composer csfixer:test
composer phpstan:test
Please see CHANGELOG for more information on what has changed recently.
This package is inspired by Laravel Subscriptions created by Laravel Cameroon and was initially started as a fork of it. After several decisions to go different ways for subscription calculation, it was rewritten from scratch, but still contains several simple methods and other code parts of the original. So if this package doesn't fit your needs, try a look into Laravel Cameroons subscription package.
The MIT License (MIT). Please see License File for more information.
How can I help you explore Laravel packages today?