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

ralphmorris's avatar

Laravel Cashier - Class 'User' not found on cancel or swap

Hello! I wonder if anybody can help me with this.

I am running Laravel 5.2 and have just installed Laravel Cashier 6.0 and added my Stripe test api keys.

I am able to add a subscription with the following code in my Subscriptions Controller

$user->newSubscription('main', 'monthly')->create($request->stripeToken);

However I have tried using the cancel and swap methods and both a giving me FatalThrowableError in Model.php line 797: Class 'User' not found. I can't see any error is User.php and the rest of the sites which interacts with the User model works fine.

One thing I noticed was that I seem to be using the stripe API v1. As the url in their test log is /v1/customers/cus_ANxDjbcYhXtnPw/subscriptions. Is this correct? Is there somewhere in Cashier where I can set the version of the API?

My update method looks like this.

    public function update(Request $request)
    {
        $user = \Auth::user();

        $user->subscription('main')->swap('yearly');

        return redirect()->back();
    }

And delete method looks like this:

    public function cancel(Request $request)
    {
        $user = \Auth::user();

        $user->subscription('main')->cancel();

        return redirect()->back();
    }

Both giving me the User not found error. But creating a subscription and viewing invoices works fine.

I appreciate this isn't much info but any help will be really appreciated! If there's more info I could give just ask.

Thanks

Ralph

0 likes
2 replies
ralphmorris's avatar

An update on this.

If I dump the below it returns the subscription fine.

dd(\Auth::user()->subscription('main'));

However it fails on this line of code, inside the cancel method.

        $subscription = $this->asStripeSubscription();

This is the asStripeSubscription() method with my dd which return the Call User not found

dd($this->user->asStripeCustomer()->subscriptions->retrieve($this->stripe_id));

If anyone can help that would be great!

ralphmorris's avatar

Well that was a ride!

If it helps anyone else - I did a dump of $this->user which still gave me the error. So I found the user method and saw the getEnv was returning User. So I tried changing to App\User in my .env and it now works fine.

I guess my only question now is is that necessary/correct? Might be a stupid question but would be good to have someone confirm.

Thanks

Please or to participate in this conversation.