Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

sayedsahin's avatar

Attempted to lazy load [owner] on model [Laravel\\Cashier\\Subscription] but lazy loading is disabled.

I used Model::preventLazyLoading() in my laravel app. I get this error when I request to cancel a subscription. My code: $result = $user->subscription($subscription->name)->cancel();

0 likes
5 replies
martinbean's avatar

@sayedsahin You’re prohibited lazy loading, and you’ve got an error that a relation was attempted to be lazy-loaded. That’s how it works?

You therefore need to eager-load the relation that there was an attempt to access.

martinbean's avatar

@sayedsahin And? You’ve disabled lazy-loading, but that code tries to lazy-load a relation, hence the error. The feature is doing literally what it’s meant to do. It’s like locking your door and then complaining you’re locked out of your house.

Solution? Eager-load the relation:

$user->loadMissing('subscriptions.owner');
4 likes
alinlinca's avatar

@sayedsahin Yeah, your code work perfectly because you have one record in DB for that subscription. The problem with this is when in DB are multiple records and need to load.

In my case, I have a subscription that was canceled, and then the user subscribes again, and for me the problem was when the second subscription became past_due and the user had to confirm the payment. And when I was calling $subscription->latestPayment(), I had to load the relationships first.

@martinbean solution works perfectly!

Snapey's avatar

This disabling of eager loading is only active in development so in production it will work without issue, but might be causing an n+1 issue.

Please or to participate in this conversation.