Oct 1, 2021
0
Level 5
Laravel Cashier - Eager loading owner not possible
In my Laravel's AppServiceProvider.php I have disabled lazy loading:
//AppServiceProvider.php
Model::preventLazyLoading(! $this->app->isProduction());
This will throw an exception every time a n+1 problem arises.
I am then using Laravel Cashier package to handle subscriptions in my application. I am using the official methods, and trying to get a subscription as a Stripe subscription:
$subscription = auth()->user()->subscription('monthly');
return $subscription->asStripeSubscription();
The above gives me this error:
Attempted to lazy load [owner] on model [Laravel\Cashier\Subscription] but lazy loading is disabled.
The asStripSubscription method looks like this, and is located in this file:
public function asStripeSubscription(array $expand = [])
{
return $this->owner->stripe()->subscriptions->retrieve(
$this->stripe_id, ['expand' => $expand]
);
}
Please or to participate in this conversation.