Level 39
However the code above not always saves the stripe id
or stripe->id was null
test / dump it before save
1 like
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
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
Please or to participate in this conversation.