I have this code below that gets all of a user's cardId which I need to make an api call to get details of each card.The cardIds are saved when a card is created.
The endpoint to get a card is this-
https://{baseUrl}/v3/virtual-cards/id where i need to pass the user's cardId as id.
In my application I am making it possible for a user to create multiple cards so on creation of a card I collect the cardId and save it to my database. I can get all the cardIds from the database using
$auth_user = Auth::user()->id;
$card = Card::where('user_id', $auth_user)->pluck('card_id');
Now I want to loop over all the cardIds in the database to make the api call getting all the datails for each cardId. What i have tried.
public function getCard(Request $request){
$auth_user = Auth::user()->id;
$card = Card::where('user_id', $auth_user)->pluck('card_id');
foreach ($card as $userCard) {
$response = Http::withToken('{SEC_KEY}')->get('https://{baseUrl}/v3/virtual-cards/$userCard', [
]);
return $response->json();
}
}
But the foreach does not seem to work.