Gabotronix
5 months ago
537
4
General

Call to a member function getKey() on string when collecting an array

Posted 5 months ago by Gabotronix

Hi everybody, I'm trying to turn an associative array into a collectin in order to merge it with a collection, but for some reason I'm getting the following error:

Call to a member function getKey() on string

My code:

$posts = Post::with(['category', 'user'])->get();

$toMerge = collect([ 'video' => '/img/misc/doggo.mp4', 'component' => 'slider-item-2' ]);

$mergedPosts = $posts->merge($toMerge);

Please sign in or create an account to participate in this conversation.