Skip to content
Advertisement

Laravel – convert array into eloquent collection

I need to use data from an API.

I create a function:

JavaScript

and dd($vouchers) return me:

enter image description here

Now when I try to use $vouchers array with blade engine like:

JavaScript

I got error:

JavaScript

How I can convert array into eloquent collection. I use the latest Laravel 5.7 version

Advertisement

Answer

Actually your $vouchers is an array of arrays,

So you may want to convert your sub-arrays to objects:

You can do it simply using:

JavaScript

.. or using collections:

JavaScript

Laravel collections documentation

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