Skip to content
Advertisement

Larave error: array_merge(): Expected parameter 2 to be an array, string given

Hi fellow Laravel developers: The following is the output of dd(session(‘cart’)); :

JavaScript

Later on id like to save the cart as single rows in the orders table. In preparation of this … When i do the following:

JavaScript

The Browser shows (very short) the first iteration of the foreach “001” ($data[‘nr’]), and then I get this Error:

array_merge(): Expected parameter 2 to be an array, string given.

My Question: What is meant by parameter 2?

Advertisement

Answer

You can do by this:

JavaScript

Another way:

You can use pluck the key you want:

JavaScript

More information with collection you can check it at here:

https://laravel.com/docs/8.x/collections

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement