Weave 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

Thunder Pack Laravel Package

bachisoft/thunder-pack

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require bachisoft/thunder-pack
    php artisan vendor:publish --provider="BachiSoft\ThunderPack\ThunderPackServiceProvider"
    php artisan migrate
    
  2. Configure Tenancy

    • Add Tenantable trait to your User model:
      use BachiSoft\ThunderPack\Traits\Tenantable;
      class User extends Authenticatable { use Tenantable; }
      
    • Set default tenant in .env:
      THUNDERPACK_DEFAULT_TENANT=1
      
  3. First Use Case: Tenant Switching

    use BachiSoft\ThunderPack\Facades\ThunderPack;
    
    // Switch tenant via ID
    ThunderPack::switchTenant(2);
    
    // Or via user (automatically resolves tenant)
    ThunderPack::switchTenant($user);
    
  4. Verify Installation

    • Check tenants table exists
    • Test tenant isolation with:
      $tenant1 = Tenant::find(1);
      $tenant2 = Tenant::find(2);
      $tenant1->users()->count(); // Should return only users for tenant 1
      

Implementation Patterns

Core Workflows

1. Tenant Management

  • Automatic Tenant Resolution
    // In middleware or service provider
    ThunderPack::resolveTenantFromSession();
    
  • Super Admin Bypass
    if (auth()->user()->isSuperAdmin()) {
        ThunderPack::disableTenantIsolation();
        // Access all tenants' data
    }
    

2. Subscription Lifecycle

  • Create Subscription
    $subscription = ThunderPack::createSubscription($tenant, [
        'plan' => 'pro',
        'trial_days' => 14,
        'billing_cycle' => 'monthly'
    ]);
    
  • Handle Payment Events
    // In webhook controller
    ThunderPack::handlePaymentEvent($paymentData, $tenant);
    
  • Check Subscription Status
    if ($tenant->subscription->isActive()) {
        // Grant access
    }
    

3. Feature/Limit Enforcement

  • Check Feature Flag
    if ($tenant->hasFeature('custom_branding')) {
        // Enable custom branding
    }
    
  • Validate Limits
    if ($tenant->checkLimit('max_projects', 5)) {
        // Allow project creation
    } else {
        abort(403, 'Project limit exceeded');
    }
    

4. WhatsApp Integration

  • Send Message
    ThunderPack::sendWhatsAppMessage($tenant, '1234567890', 'Hello from SaaS!');
    
  • Template Messages
    ThunderPack::sendWhatsAppTemplate($tenant, 'welcome', ['name' => 'John']);
    

Integration Tips

Middleware Setup

// app/Http/Kernel.php
protected $middlewareGroups = [
    'web' => [
        // ...
        \BachiSoft\ThunderPack\Http\Middleware\ResolveTenant::class,
        \BachiSoft\ThunderPack\Http\Middleware\CheckSubscription::class,
    ],
];

API Rate Limiting

// In route middleware
ThunderPack::checkRateLimit('api_calls_per_month', 1000);

Custom Limits

Extend the limits system via events:

// Event listener
ThunderPack::listen('tenant.limit.violation', function ($tenant, $limitName) {
    // Log or notify admin
});

Tenant-Specific Models

class Project extends Model {
    use BelongsToTenant; // Automatically scopes to current tenant

    public function tenant() {
        return $this->belongsTo(Tenant::class);
    }
}

Gotchas and Tips

Pitfalls

  1. Tenant Isolation Leaks

    • Issue: Forgetting to call ThunderPack::resolveTenant() in API routes.
    • Fix: Use middleware or base controller to ensure tenant resolution.
  2. Subscription State Confusion

    • Issue: isActive() returns true for trials but not paid subscriptions.
    • Fix: Check isPaid() separately or use isValid() for both.
  3. WhatsApp Credentials

    • Issue: Missing .env config for WhatsApp API.
    • Fix:
      WHATSAPP_API_KEY=your_key
      WHATSAPP_PHONE_NUMBER=+1234567890
      
  4. Limit Caching

    • Issue: Limits not updating in real-time.
    • Fix: Clear cache after limit changes:
      ThunderPack::clearTenantCache($tenant);
      
  5. Super Admin Scope

    • Issue: Accidental data leaks when disableTenantIsolation() is left enabled.
    • Fix: Wrap in explicit checks:
      if (auth()->user()->isSuperAdmin()) {
          ThunderPack::disableTenantIsolation();
          // Critical: Re-enable after access
          ThunderPack::enableTenantIsolation();
      }
      

Debugging Tips

  1. Tenant Resolution

    php artisan tinker
    >>> \BachiSoft\ThunderPack\Facades\ThunderPack::getCurrentTenant();
    
  2. Subscription Logs

    $tenant->subscription->logs()->latest()->take(5)->get();
    
  3. Limit Violations

    event(new \BachiSoft\ThunderPack\Events\LimitViolation($tenant, 'max_projects'));
    // Check logs for debug output
    
  4. WhatsApp Debugging

    WHATSAPP_DEBUG=true
    
    • Enables verbose logging in storage/logs/thunderpack-whatsapp.log.

Extension Points

  1. Custom Tenant Fields

    // Extend Tenant model
    class Tenant extends \BachiSoft\ThunderPack\Models\Tenant {
        protected $casts = [
            'custom_field' => 'boolean',
        ];
    }
    
  2. Custom Subscription Plans

    // Publish and extend config
    php artisan vendor:publish --tag=thunderpack-config
    // Add to config/thunderpack.php
    'plans' => [
        'custom_plan' => [
            'price' => 99.99,
            'features' => ['advanced_reports'],
        ],
    ],
    
  3. Custom Limit Types

    // Register new limit type
    ThunderPack::extend('custom_limit', function ($tenant, $value) {
        return $tenant->custom_metric >= $value;
    });
    
  4. Override Tenant Resolution

    // In service provider
    ThunderPack::macro('resolveTenant', function () {
        return Tenant::where('domain', request()->getHost())->first();
    });
    
  5. Webhook Handling

    // Extend payment event handling
    ThunderPack::extendPaymentHandler('stripe', function ($data) {
        // Custom Stripe logic
    });
    
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.
htinlynn/genius-helper
maco-studios/hephaestus
elmogy/larafast
xeviant/laravel-paystack
gorilladash/laravel-website-sdk
martialbe/flysystem-oss
chondal/3312client
jeroen-g/flickr
opscale-co/nova-genbi
itsjustvita/laravel-retention
tequilarapido/trackit
gregsphotography/site-builder-filament
cabaoctavio/laravel-query-log
gregsphotography/site-builder-components
io-digital/clickatell
snowsoft/laravel-admin
oxygen/auth
relicsoftware/barakah-payment-gateway
tobya/work-with-composer
equipc/laravel-email-validator