src/Entity.php
public static function make($data = null, $index = null, Closure $modifier = null)
    {
        if ($data instanceof Traversable) {
            $data = iterator_to_array($data);
        }

        if (!is_array($data)) {
            return null;
        }

        if (count($data) < 1) {
            return [];
        }

        // Check if it is a multi dimensional array
        $values = array_values($data);
        $multi  = array_key_exists(0, $values) && is_array($values[0]);


        if ($multi) {
            $list = [];
            foreach ($data as $item) {
                if ($index && array_key_exists($index, $item)) {
                    $key        = $item[$index];
                    $list[$key] = static::populate($item, $modifier);
                    continue;
                }
                $list[] = static::populate($item, $modifier);
            }

            return $list;
        }

        return static::populate($data, $modifier);
    }
public static function make($data = null, $index = null, Closure $modifier = null)
    {
        if ($data instanceof Traversable) {
            $data = iterator_to_array($data);
        }

        if (!is_array($data)) {
            return null;
        }

        if (count($data) < 1) {
            return [];
        }

        // Check if it is a multi dimensional array
        $values = array_values($data);
        $multi  = array_key_exists(0, $values) && is_array($values[0]);


        if ($multi) {
            $list = [];
            foreach ($data as $item) {
                if ($index && array_key_exists($index, $item)) {
                    $key        = $item[$index];
                    $list[$key] = static::populate($item, $modifier);
                    continue;
                }
                $list[] = static::populate($item, $modifier);
            }

            return $list;
        }

        return static::populate($data, $modifier);
    }
public static function make ( $ data = null , $ index = null , Closure $ modifier = null ) { if ( $ data instanceof Traversable ) { $ data = iterator_to_array ( $ data ) ; } if ( ! is_array ( $ data ) ) { return null ; } if ( count ( $ data ) < 1 ) { return [ ] ; } // Check if it is a multi dimensional array $ values = array_values ( $ data ) ; $ multi = array_key_exists ( 0 , $ values ) && is_array ( $ values [ 0 ] ) ; if ( $ multi ) { $ list = [ ] ; foreach ( $ data as $ item ) { if ( $ index && array_key_exists ( $ index , $ item ) ) { $ key = $ item [ $ index ] ; $ list [ $ key ] = static :: populate ( $ item , $ modifier ) ; continue ; } $ list [ ] = static :: populate ( $ item , $ modifier ) ; } return $ list ; } return static :: populate ( $ data , $ modifier ) ; }
Convert array to entities

@param  array   $data
@param  string  $index    Set the value in this key as index
@param  Closure $modifier Executed before the entity gets populated

@return Entity|array
Convert array to entities