4

First time user of Laravel Cashier (version 11 and Laravel v6.x). There are two tables provided part of the standard migration of Cashier; subscriptions and subscription_items.

I just wanted to understand clearly what is the purpose of the subscription_items table. I understand that the subscriptions table stores the subscription details we created using the Cashier API. However I noticed that the subscription_items table stores pretty identical records but with lesser detail.

Can anyone explain?

To give some context, the subscription plans in my app is very simple. Basically between Free and Paid plan of $10/month with 14-day free trial.

user2268244
  • 244
  • 1
  • 15

1 Answers1

1

When a subscription has multiple plans, it will have multiple subscription "items" stored in your database's subscription_items table. You may access these via the items relationship on the subscription:

$user = User::find(1);

$subscriptionItem = $user->subscription('default')->items->first();

// Retrieve the Stripe plan and quantity for a specific item...
$stripePlan = $subscriptionItem->stripe_plan;
$quantity = $subscriptionItem->quantity;

go through the doc: https://laravel.com/docs/7.x/billing#creating-subscriptions