When using Laravel Cashier/Stripe should I move the billable trait off the User model when that user buys subscriptions for a related model?

  laravel, laravel-cashier, stripe-payments

So my client has a discord bot that manages discord servers on behalf of the user. The relationship on the Laravel end is each User model hasMany() Server models. Each of those Server models may either be on the free plan, or a paid subscription plan on a per-Server basis.

So a User might have 6 related Servers:

  • 3 on the basic $0 plan
  • 2 on the $5/mo advanced plan
  • 1 on the $10/mo expert plan

In this case one entity (the User) is paying for all of these, but the discord bot will be querying our API on a per Server basis to check that particular Server’s current subscription plan.

So any recommendations on how to organize this with Cashier/Stripe.

Do I apply the billable trait to the User model (since they are being billed), and then use something like the metadata field on newSubscription() to try and sort which server the the subscription actually applies to

'metadata' => [
    'server_id' => 'Some server id'
]

Or do I apply the billable trait to the Server model (since they are the ones that have a particular subscription plan, and will be queried against). In which case will I still be able to create one billing portal for a user to manage all of their subscriptions?

Any advice would be much appreciated! Thanks much.

Source: Laravel

Leave a Reply