I have a collection based on a property of a that collection i would like to make two extra collections and push it to response collection.
For example
$user = collect([
"ID" => 4944,
"reason" => "Friend Referral",
"created_at" => "2016-08-29 18:23:53",
"updated_at" => "2016-08-29 18:23:53",
"type" => "credit",
"amount" => "100",
"usageCount" => 1
]);
$credits = collect([]);
$credits->push($user);
if ($user->get('usageCount')) {
$user->put('type','debit');
$credits->push($user);
}
I get the credits collection as the following
[
{
"ID": 4944,
"reason": "Friend Referral",
"created_at": "2016-08-29 18:23:53",
"updated_at": "2016-08-29 18:23:53",
"type": "debit",
"amount": "100",
"usageCount": 1
},
{
"ID": 4944,
"reason": "Friend Referral",
"created_at": "2016-08-29 18:23:53",
"updated_at": "2016-08-29 18:23:53",
"type": "debit",
"amount": "100",
"usageCount": 1
}
]
The type should be credit and debit, but somehow i am pushing the debit type make the first array as type debit as well.
I don't understand.