public function bulkSerialise($model)
    {
        $class = get_class($model);
        if (!$model instanceof Model) {
            throw new InvalidOperationException($class);
        }
        // dig up metadata
        if (!isset(self::$metadataCache[$class])) {
            self::$metadataCache[$class] = $model->metadata();
        }
        $meta = self::$metadataCache[$class];
        $keys = array_keys($meta);
        // dig up getter list - we only care about the mutators that end up in metadata
        if (!isset(self::$mutatorCache[$class])) {
            $getterz = [];
            $datez = $model->getDates();
            $castz = $model->retrieveCasts();
            foreach ($keys as $key) {
                if ($model->hasGetMutator($key) || in_array($key, $datez) || array_key_exists($key, $castz)) {
                    $getterz[] = $key;
                }
            }
            self::$mutatorCache[$class] = $getterz;
        }
        $getterz = self::$mutatorCache[$class];
        $modelAttrib = $model->getAttributes();
        $result = array_intersect_key($modelAttrib, $meta);
        foreach ($keys as $key) {
            if (!isset($result[$key])) {
                $result[$key] = null;
            }
        }
        foreach ($getterz as $getter) {
            $result[$getter] = $model->$getter;
        }

        return $result;
    }
public function bulkSerialise($model)
    {
        $class = get_class($model);
        if (!$model instanceof Model) {
            throw new InvalidOperationException($class);
        }
        // dig up metadata
        if (!isset(self::$metadataCache[$class])) {
            self::$metadataCache[$class] = $model->metadata();
        }
        $meta = self::$metadataCache[$class];
        $keys = array_keys($meta);
        // dig up getter list - we only care about the mutators that end up in metadata
        if (!isset(self::$mutatorCache[$class])) {
            $getterz = [];
            $datez = $model->getDates();
            $castz = $model->retrieveCasts();
            foreach ($keys as $key) {
                if ($model->hasGetMutator($key) || in_array($key, $datez) || array_key_exists($key, $castz)) {
                    $getterz[] = $key;
                }
            }
            self::$mutatorCache[$class] = $getterz;
        }
        $getterz = self::$mutatorCache[$class];
        $modelAttrib = $model->getAttributes();
        $result = array_intersect_key($modelAttrib, $meta);
        foreach ($keys as $key) {
            if (!isset($result[$key])) {
                $result[$key] = null;
            }
        }
        foreach ($getterz as $getter) {
            $result[$getter] = $model->$getter;
        }

        return $result;
    }
public function bulkSerialise ( $ model ) { $ class = get_class ( $ model ) ; if ( ! $ model instanceof Model ) { throw new InvalidOperationException ( $ class ) ; } // dig up metadata if ( ! isset ( self :: $ metadataCache [ $ class ] ) ) { self :: $ metadataCache [ $ class ] = $ model -> metadata ( ) ; } $ meta = self :: $ metadataCache [ $ class ] ; $ keys = array_keys ( $ meta ) ; // dig up getter list - we only care about the mutators that end up in metadata if ( ! isset ( self :: $ mutatorCache [ $ class ] ) ) { $ getterz = [ ] ; $ datez = $ model -> getDates ( ) ; $ castz = $ model -> retrieveCasts ( ) ; foreach ( $ keys as $ key ) { if ( $ model -> hasGetMutator ( $ key ) || in_array ( $ key , $ datez ) || array_key_exists ( $ key , $ castz ) ) { $ getterz [ ] = $ key ; } } self :: $ mutatorCache [ $ class ] = $ getterz ; } $ getterz = self :: $ mutatorCache [ $ class ] ; $ modelAttrib = $ model -> getAttributes ( ) ; $ result = array_intersect_key ( $ modelAttrib , $ meta ) ; foreach ( $ keys as $ key ) { if ( ! isset ( $ result [ $ key ] ) ) { $ result [ $ key ] = null ; } } foreach ( $ getterz as $ getter ) { $ result [ $ getter ] = $ model -> $ getter ; } return $ result ; }
Serialise needed bits of supplied model, taking fast path where possible.

@param  $model

@return mixed
Serialise needed bits of supplied model taking fast path where possible .