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

jwcd's avatar
Level 1

Laravel Cashier - overwriting findBillable

Hi everyone,

I'm absolutely thrilled that there's amazing open source packages like cashier-stripe out there, however for my implementation I'm in a situation where I'm not sure what the best way forward is, with Cashier.

I have a multi-tenancy application where each "user" can be part of multiple tenants, so their stripe_id is stored in a link table per tenant, meaning the "stripe_id" column remains empty.

This all works fine, except for webhooks, where Cashier's static function "findBillable" is using a query on that column to find the billable object. This is where my conundrum lies, as I have a couple of options:

  • work with 1 stripe_id -> not possible
  • capture the where() function on the User model, specifically for the use case in the findBillable static method -> i feel like that's way too much of a hack and does not provide certainty other methods in Cashier (or future methods) will work as well
  • override the static function Cashier::findBillable -> so far, I believe this is not possible in PHP
  • make a fork of Cashier to alter this function

Currently I'm going with the last option, although it feels like overkill, it does feel like the most clean option going forward.

If anyone has insights on how to tackle this, any feedback would be very much appreciated.

0 likes
4 replies
srasch's avatar

I don't know exactly what you need but IMHO you can achieve it maybe with two ways:

  1. Maybe it''s enough to simply change the billable model in your .env-file: https://laravel.com/docs/8.x/billing#billable-model

  2. Extend the Cashier class like this:

<?php


namespace App\Helpers;


use Laravel\Cashier\Cashier;


class CustomCashier extends Cashier
{
    public static function findBillable( $stripeId )
    {

       // your changes
    }
}
jwcd's avatar
Level 1

Hey SRASCH, Thanks for your reply, I need to edit that function because of the Cashier webhooks that Stripe is hitting, in the webhooks, the Cashier flow is triggered and that function is hit. Swapping out Cashier.php with a custom one is an option if there was a way to inject that class back into the Cashier package. Because only then I'm confident that that function is always the updated one, and not just where I'm using it for.... does that make sense?

jwcd's avatar
Level 1

Swapping out the billable object might be an option though, to then proxy the "User" object through that other Billable model.... food for thought, thanks!

srasch's avatar

You could inject the original findBillablemethod if you set a condition to your custom and/or call it itself:

<?php


namespace App\Helpers;


use Laravel\Cashier\Cashier;


class CustomCashier extends Cashier
{
    public static function findBillable( $stripeId, $something )
    {

	if($something) {
           
            // return $whatEverYouWant;
           // or make something cool and return nothing here
        }

        return parent::findBillable($stripeId);       

    }
}

Please or to participate in this conversation.