Hello,
To extract the subscription IDs from the $subscript object and pass them to your Blade view, you can loop through the results and collect the IDs into an array. Then, you can pass this array to the view. Here's how you can do it:
$stripe = new StripeClient(env('STRIPE_SECRET'));
// Search for subscriptions using the Stripe API
$subscript = $stripe->subscriptions->search([
'query' => 'metadata["user_id"]:"' . $user->id . '"'
]);
// Initialize an array to hold subscription IDs
$subscriptionIds = [];
// Loop through the search results and collect the subscription IDs
foreach ($subscript->autoPagingIterator() as $subscription) {
$subscriptionIds[] = $subscription->id;
}
// Pass the subscription IDs to the view
return view('user.profile', ['subscriptionIds' => $subscriptionIds]);
In your Blade view (user.profile), you can then display the subscription IDs like this:
<h1>User Subscriptions</h1>
<ul>
@foreach($subscriptionIds as $id)
<li>{{ $id }}</li>
@endforeach
</ul>
This will render an unordered list of subscription IDs on the user's profile page.
Remember to handle any potential exceptions that might occur when interacting with the Stripe API, such as network issues or incorrect credentials. You can do this by wrapping your Stripe API calls in a try-catch block.
Also, ensure that you have the necessary permissions to access the user's subscription information and that you're complying with all relevant privacy laws and Stripe's terms of service.