rinvex/laravel-subscriptions

Problem with surcharged models (multi-tenancy architecture)

lcandellier opened this issue · 2 comments

Problem : i'm in multi-tenancy architecture with database by client. I've changed models in config to use supercharged models with connection forced on central database.

use Rinvex\Subscriptions\Models\Plan as parentPlan; class Plan extends parentPlan { protected $connection = 'central'; }

All is working, but when I call the recordFeatureUsage with a subscription on central database, the request try to persist on the tenant database.

Base table or view not found: 1146 Table 'tenant_17827c45-1a6c-456e-9f90-39b280ed9f62.plan_subscriptions' doesn't exist (SQL: select count(*) as aggregate fromplan_subscriptionswhereid= 1)",

In function recordFeatureUsage, i've dumped $usage just before $usage->save() and it's on central connection

App\Models\Central\Admin\PlanSubscriptionUsage {#4462 #connection: "central"

Have you an idea ?

The problem is in rules, ;-)

        'subscription_id' => 'required|integer|exists:'.config('rinvex.subscriptions.tables.plan_subscriptions').',id',
        'feature_id' => 'required|integer|exists:'.config('rinvex.subscriptions.tables.plan_features').',id',

so I will surcharge the constructor with specified rules ;-)

Glad you found your way around, don't hesitate to ask for any further assistance 👍