Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Plans Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • SaaS Subscription Core: The package excels as a subscription management layer for SaaS applications, decoupling plan/feature logic from billing/payment systems. It aligns well with Laravel’s Eloquent ecosystem and leverages traits for modular integration.
  • Feature-First Design: Supports both countable (e.g., tokens, credits) and uncountable (e.g., access flags) features, with configurable reset intervals. This is ideal for tiered SaaS models (e.g., "Basic + 1000 API calls").
  • Event-Driven Extensibility: Emits events (SubscriptionCreated, SubscriptionRenewed) for seamless integration with external billing systems (Stripe, custom, etc.). This avoids vendor lock-in.
  • Localization Support: Uses spatie/laravel-translatable for multilingual plans/features, reducing frontend duplication.

Integration Feasibility

  • Laravel Native: Built for Laravel (v10+), with zero configuration for core functionality. Uses Eloquent models, migrations, and service providers.
  • Billing Agnostic: Explicitly does not handle payments/invoices, forcing a clean separation. Requires a separate billing system (e.g., Stripe, custom) to listen to events and generate invoices.
  • Migration Path:
    • Greenfield: Install via Composer, run migrations, and implement HasSubscriptions trait.
    • Brownfield: Requires mapping existing subscriptions/plans to the new schema (e.g., via data migrations or seeders).
  • Dependencies:
    • Core: Laravel, PHP 8.1+, Eloquent.
    • Optional: spatie/eloquent-sortable (for ordering), spatie/laravel-translatable (for localization).
    • No heavy libraries (e.g., no queues, caching, or complex state machines).

Technical Risk

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.

Key Questions for TPM

  1. Billing System Compatibility:

    • How will we integrate with [Stripe/PayPal/custom]? Are there existing event listeners or will we build them?
    • Do we need to support prorated billing for partial periods (e.g., mid-month upgrades)?
  2. Feature Usage Tracking:

    • How will we audit feature consumption (e.g., API calls, storage)? Does the package’s FeatureUsage model suffice?
    • What’s the strategy for overage charges (e.g., if a user exceeds their token limit)?
  3. Plan Management Workflow:

    • How will we handle plan updates (e.g., price changes, feature additions)? Will we use the package’s renew() or a custom migration?
    • Do we need versioning for plans (e.g., to grandfather existing users into old pricing)?
  4. Scaling Considerations:

    • How many plans/features/subscriptions will we support at launch? (Affects database indexing.)
    • Will we need to cache plan lists (e.g., for checkout pages) to reduce query load?
  5. Localization Needs:

    • Do we need multilingual plans/features? If not, can we disable the translatable dependency?
    • How will we handle currency localization (e.g., € vs. $) for prices?
  6. Testing Strategy:

    • How will we test feature consumption (e.g., token limits) and subscription transitions (e.g., downgrades)?
    • Do we need to mock the billing system during tests?
  7. Monitoring/Alerts:

    • What metrics will we track (e.g., failed subscriptions, feature overuse)?
    • How will we alert on expiring subscriptions or low feature balances?

Integration Approach

Stack Fit

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).

Migration Path

  1. Assessment Phase:

    • Audit existing subscription logic (e.g., custom tables, business rules).
    • Map current plans/features to the package’s schema (e.g., Plan, Feature, Subscription).
  2. Setup:

    composer require lacodix/laravel-plans
    php artisan vendor:publish --provider="Lacodix\LaravelPlans\LaravelPlansServiceProvider"
    php artisan migrate
    
    • Configure .env (e.g., PLANS_PRICE_PRECISION=2).
  3. Data Migration:

    • Option A: Write a seeder to import existing plans/subscriptions.
    • Option B: Use a data migration to transform old schema to new (e.g., users_subscriptionssubscriptions).
  4. Trait Implementation:

    // app/Models/User.php
    use Lacodix\LaravelPlans\Models\Traits\HasSubscriptions;
    class User extends Authenticatable {
        use HasSubscriptions;
    }
    
  5. Billing Integration:

    • Register event listeners for SubscriptionCreated, SubscriptionRenewed:
      // app/Listeners/CreateStripeSubscription.php
      public function handle(SubscriptionCreated $event) {
          Stripe::createSubscription($event->subscription);
      }
      
  6. Feature Consumption:

    • Implement logic to track usage (e.g., middleware for API routes):
      $user->consumeFeature('tokens', 10);
      
  7. Testing:

    • Write feature tests for:
      • Plan subscription/renewal/cancellation.
      • Feature consumption limits.
      • Billing event triggers.

Compatibility

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.

Sequencing

  1. Phase 1: Core Setup (2–3 sprints)

    • Install package, run migrations, implement HasSubscriptions.
    • Migrate existing plans/features to new schema.
    • Build basic subscription flows (subscribe/renew/cancel).
  2. Phase 2: Billing Integration (1–2 sprints)

    • Implement event listeners for Stripe/PayPal/custom billing.
    • Test prorated billing for partial periods.
  3. Phase 3: Feature Management (1–2 sprints)

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
calmfox/watch-sylius
damienfern/grpc-symfony-bundle
atoolo/index-bundle
atoolo/genai-bundle
coprotoai/laravel-ticket
davidjln/llm-carbon-bundle
cryonighter/valid-request-bundle
coolms/taxonomy-bundle
coolms/field-bundle
articulate-orm/symfony
aaix/laravel-tall-architect
ephoto/akeneo-connector
emmanuelballery/eb-plantumlbundle
emielburgman/symfony-visitor-beacon
emielburgman/symfony-visit-storage
emielburgman/symfony-security-headers
emielburgman/symfony-log-viewer
emarref/xdebug-bundle
emarref/pubnub-bundle
elriseio/finance-money-bundle