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

Zeph's avatar
Level 8

How to insert a new model on subscription creation

Hello,

I want to insert a new model after the user subscribes for a plan. I'm using Cashier - Stripe and this is my code:

$subscription = $request->user()->newSubscription('main', $plan->stripe_id)
		->create($request->token);

if ( $subscription->stripe_status == 'active' ) {

			Website::create(
				[
					'user_id' => $request->user()->id,
					'stripe_subscription' => $subscription->stripe_id,
					'url' => $request->get('url'),
					'uuid' => $uuid
				]
			);

		} 

However the code above not always saves the stripe id and when I check the DB it shows:

| id | user_id | stripe_subscription          | uuid        | url              |
|----|---------|------------------------------|-------------|------------------|
| 1  | 1       | sub_1KtNTfIa65c9jPZdC3NvmOp1 | xxx-xxx-xxx | https://url.com  |
| 2  | 1       | NULL                         | yyy-yyy-yyy | https://url2.com |
|    |         |                              |             |                  |

Any help would be appreciated!

Thanks

0 likes
2 replies
sr57's avatar

However the code above not always saves the stripe id

or stripe->id was null

test / dump it before save

1 like
Zeph's avatar
Level 8

@sr57 Thanks, I solved it. I noticed that the stripe_subscription wasn't part of the fillable property in my model

Please or to participate in this conversation.