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

PeterF's avatar

Laravel Cashier, Billable Trait, createSetupIntent and VSCode

I have a fresh install of Laravel Cashier, via composer, and setup all my stripe stuff. My problems are at the laravel end, or maybe the VSCode end....

Problem 1. As per a post from someone else here a week ago, when I tried to add the Billable intent to the User object, my VSCode kept objecting saying that it was not a known class. And that was with the "Use" statement in the file.

The way fixed that, was to navigate, in vscode, into vendors/laravel/cashier and open the Billable.php file with vscode and then it believed me that it was a real class.

Problem 2. Then I add the following function to a brand new controller.....

public function index()
    {
        $data = [
            'intent' => Auth::user()->createSetupIntent()
        ];

        return view('subscriptions.payment')->with($data);
    }

And now VSCode has put the red squiggle under "createSetupIntent()" and told me it's an undefined method. Sadly for this one, no amount of poking around in the vendor package will make it be recognised.....

Any ideas? There were no errors from Composer, I am running 13.6 of cashier......

0 likes
5 replies
martinbean's avatar

@peterf It’s just VS Code reading type hints and return types verbatim.

What the issue will be is, yes, you’ve added the Billable trait to your User model, but Auth::user() will have a return type saying it returns an Authenticatable interface or something*. So VS Code will be reading that, seeing that interface doesn’t have a createSetupIntent method (even though the class implementing that interface may). So it’s just VS Code not being able to infer that method will return a User instance at runtime.

* It does: https://github.com/laravel/framework/blob/3f5d3704507f278ffc1231c32a74f0eb86eb0584/src/Illuminate/Support/Facades/Auth.php#L12

martinbean's avatar

@raihan004 There is no “solution”. The return type for Auth::user is the Authenticatable. VS Code is just reading the information it is being given, as Auth::user could potentially return a class other than the User model but still implements the Authenticatable interface.

If you want to be explicit and tell VS Code that, hey, yes, Auth::user just says it returns an Authenticatable implementation but I can guarantee it will always actually be a User model instance, then you can use an inline docblock:

/** @var \App\Models\User $user */
$user = Auth::user();

// VS Code will no longer complain about this...
$setupIntent = $user->createSetupIntent();

// But if Auth::user() returns something other than a User model instance,
// your application will throw an error
1 like
zeebwp's avatar

@martinbean try this but not work . in my case i have laravel 5.7 . actually createSetupIntent() not in \vendor\laravel\cashier\src\Billable.php this trait is there any alter solution ? i

martinbean's avatar

@zeebwp Dude. You should update your application as soon as possible. Laravel 5.7 is ancient and has long been unsupported.

Please or to participate in this conversation.