looks more like a json object than a php collection?
May 12, 2019
6
Level 1
Call to a member function getKey() on string while merging two collections
i have one eloquent query returning the below response as json [{"type":"mangoes","count":3},{"type":"bananas","count":4},{"type":"apples","count":1}]
when i try to merge the collection with a new collection below $avacado= collect(['type'=>avacado','count'=>2l]);
i get this error member function getKey()
to merge i used
$merged = $result->merge($avacado);
Level 1
No need to merge.Just push the collection
$addtooldcollection=collect(['type'=>'avacado','count'=>2]);
$myoldcollection->push($addtooldcollection);
3 likes
Please or to participate in this conversation.