protected function getFieldsDelta(array $fieldsA, array $fieldsB)
    {
        $currentFields = Collect($fieldsB)->keyBy('name');
        $currentFieldNames = $currentFields->keys()->toArray();

        $requestedFields = Collect($fieldsA)->keyBy('name');
        $requestedFieldNames = $requestedFields->keys()->toArray();

        $updatedFields = $currentFields->whereIn('name', $requestedFieldNames)->all();

        $addedFields = $requestedFields->reject(function ($requestedField) use ($currentFieldNames) {
            return in_array($requestedField->name, $currentFieldNames);
        })->all();

        $deletedFields = $currentFields->reject(function ($currentFields) use ($requestedFieldNames) {
            return in_array($currentFields->name, $requestedFieldNames);
        })->all();

        $fieldChanges = [];

        foreach ($updatedFields as $key => $updatedField) {
            $fieldChanges[] = FieldMigrationChange::compare($updatedField, $requestedFields[$key]);
        }

        foreach ($addedFields as $addedField) {
            $fieldChanges[] = FieldMigrationChange::getAdded($addedField);
        }

        foreach ($deletedFields as $deletedField) {
            $fieldChanges[] = FieldMigrationChange::getDeleted($deletedField);
        }

        return $fieldChanges;
    }
protected function getFieldsDelta(array $fieldsA, array $fieldsB)
    {
        $currentFields = Collect($fieldsB)->keyBy('name');
        $currentFieldNames = $currentFields->keys()->toArray();

        $requestedFields = Collect($fieldsA)->keyBy('name');
        $requestedFieldNames = $requestedFields->keys()->toArray();

        $updatedFields = $currentFields->whereIn('name', $requestedFieldNames)->all();

        $addedFields = $requestedFields->reject(function ($requestedField) use ($currentFieldNames) {
            return in_array($requestedField->name, $currentFieldNames);
        })->all();

        $deletedFields = $currentFields->reject(function ($currentFields) use ($requestedFieldNames) {
            return in_array($currentFields->name, $requestedFieldNames);
        })->all();

        $fieldChanges = [];

        foreach ($updatedFields as $key => $updatedField) {
            $fieldChanges[] = FieldMigrationChange::compare($updatedField, $requestedFields[$key]);
        }

        foreach ($addedFields as $addedField) {
            $fieldChanges[] = FieldMigrationChange::getAdded($addedField);
        }

        foreach ($deletedFields as $deletedField) {
            $fieldChanges[] = FieldMigrationChange::getDeleted($deletedField);
        }

        return $fieldChanges;
    }
protected function getFieldsDelta ( array $ fieldsA , array $ fieldsB ) { $ currentFields = Collect ( $ fieldsB ) -> keyBy ( 'name' ) ; $ currentFieldNames = $ currentFields -> keys ( ) -> toArray ( ) ; $ requestedFields = Collect ( $ fieldsA ) -> keyBy ( 'name' ) ; $ requestedFieldNames = $ requestedFields -> keys ( ) -> toArray ( ) ; $ updatedFields = $ currentFields -> whereIn ( 'name' , $ requestedFieldNames ) -> all ( ) ; $ addedFields = $ requestedFields -> reject ( function ( $ requestedField ) use ( $ currentFieldNames ) { return in_array ( $ requestedField -> name , $ currentFieldNames ) ; } ) -> all ( ) ; $ deletedFields = $ currentFields -> reject ( function ( $ currentFields ) use ( $ requestedFieldNames ) { return in_array ( $ currentFields -> name , $ requestedFieldNames ) ; } ) -> all ( ) ; $ fieldChanges = [ ] ; foreach ( $ updatedFields as $ key => $ updatedField ) { $ fieldChanges [ ] = FieldMigrationChange :: compare ( $ updatedField , $ requestedFields [ $ key ] ) ; } foreach ( $ addedFields as $ addedField ) { $ fieldChanges [ ] = FieldMigrationChange :: getAdded ( $ addedField ) ; } foreach ( $ deletedFields as $ deletedField ) { $ fieldChanges [ ] = FieldMigrationChange :: getDeleted ( $ deletedField ) ; } return $ fieldChanges ; }
Get the field difference between two given Field arrays

@param array $fieldsA
@param array $fieldsB

@return array
Get the field difference between two given Field arrays