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.
SubscriptionCreated, SubscriptionRenewed) for seamless integration with external billing systems (Stripe, custom, etc.). This avoids vendor lock-in.spatie/laravel-translatable for multilingual plans/features, reducing frontend duplication.HasSubscriptions trait.spatie/eloquent-sortable (for ordering), spatie/laravel-translatable (for localization).| Risk Area | Assessment | Mitigation |
|---|---|---|
| Schema Changes | Migrations are provided, but existing apps may need custom adjustments. | Test migrations in staging; provide rollback plans. |
| Billing Integration | Requires custom event listeners for invoicing. | Document event payloads; provide starter listener examples. |
| Feature Consumption Logic | Countable features (e.g., tokens) require careful tracking to avoid overuse. | Use package’s consume() method; monitor feature_usage table. |
| Performance | Sortable features (plans/subscriptions) add overhead for large datasets. | Index sort_order columns; consider denormalizing for UI-heavy apps. |
| Localization Overhead | Translatable fields add complexity if unused. | Disable via config if not needed (translatable: false). |
| Concurrency | Subscription renewals/cancels must handle race conditions. | Use Laravel’s lock() or database transactions for critical operations. |
Billing System Compatibility:
Feature Usage Tracking:
FeatureUsage model suffice?Plan Management Workflow:
renew() or a custom migration?Scaling Considerations:
Localization Needs:
Testing Strategy:
Monitoring/Alerts:
| Component | Fit | Notes |
|---|---|---|
| Laravel Core | ✅ Native | Uses Eloquent, migrations, and service providers. |
| Database | ✅ MySQL/PostgreSQL/SQLite | Standard Laravel support; no custom queries. |
| Billing Systems | ✅ Event-Driven | Integrates via listeners (Stripe, custom, etc.). |
| Frontend (Blade/Vue) | ✅ Flexible | Provides plan/subscription data via Eloquent; UI logic is app-specific. |
| APIs | ✅ REST/GraphQL | Expose plans/features/subscriptions via API routes. |
| Queues | ⚠️ Optional | Events fire synchronously; async processing needed for billing/invoices. |
| Caching | ⚠️ Recommended | Cache plan lists/features for performance (e.g., Cache::remember). |
Assessment Phase:
Plan, Feature, Subscription).Setup:
composer require lacodix/laravel-plans
php artisan vendor:publish --provider="Lacodix\LaravelPlans\LaravelPlansServiceProvider"
php artisan migrate
.env (e.g., PLANS_PRICE_PRECISION=2).Data Migration:
users_subscriptions → subscriptions).Trait Implementation:
// app/Models/User.php
use Lacodix\LaravelPlans\Models\Traits\HasSubscriptions;
class User extends Authenticatable {
use HasSubscriptions;
}
Billing Integration:
SubscriptionCreated, SubscriptionRenewed:
// app/Listeners/CreateStripeSubscription.php
public function handle(SubscriptionCreated $event) {
Stripe::createSubscription($event->subscription);
}
Feature Consumption:
$user->consumeFeature('tokens', 10);
Testing:
| Compatibility Check | Status | Notes |
|---|---|---|
| Laravel 10.x | ✅ | Officially supported. |
| PHP 8.1+ | ✅ | Minimum requirement. |
| Stripe/PayPal Integration | ✅ | Via event listeners. |
| Custom Billing System | ✅ | Same as above. |
| Multi-Tenant SaaS | ✅ | Use tenant_id in subscriptions table or scope queries. |
| Localization (i18n) | ✅ | Requires spatie/laravel-translatable. |
| Sortable Plans/Subscriptions | ✅ | Uses spatie/eloquent-sortable. |
| Queue Workers | ⚠️ | Events fire synchronously; use queues for async billing. |
Phase 1: Core Setup (2–3 sprints)
HasSubscriptions.Phase 2: Billing Integration (1–2 sprints)
How can I help you explore Laravel packages today?