src/Generator/Analyzer/Steps/AnalyzeSluggableInteractive.php
protected function analyzeModelForSluggable(array $model)
    {
        $analysis = [
            'translated'              => null,
            'slug_column'             => null,
            'slug_sources_normal'     => [],
            'slug_sources_translated' => [],
        ];

        // find out whether the model has a 'slug' column, preferring the first match we find
        $slugColumns = config('pxlcms.generator.models.slugs.slug_columns', []);

        foreach ($slugColumns as $slugColumn) {

            foreach ($model['normal_attributes'] as $attribute) {
                if ($attribute == $slugColumn) {
                    $analysis['slug_column'] = $attribute;
                    $analysis['translated']  = false;
                    break 2;
                }
            }

            foreach ($model['translated_attributes'] as $attribute) {
                if ($attribute == $slugColumn) {
                    $analysis['slug_column'] = $attribute;
                    $analysis['translated']  = true;
                    break 2;
                }
            }
        }

        // discard any matches that don't have a slug column on the model
        // if there is no slug structure present (because that could never work)
        if ( ! $this->context->slugStructurePresent && empty($analysis['slug_column'])) return false;

        // find out whether the model has slug source candidate columns
        $slugSources = config('pxlcms.generator.models.slugs.slug_source_columns', []);

        // make sure we keep slug and source column in the same model (translated or parent)
        $analysis['slug_sources_translated'] = array_values(array_intersect($slugSources, $model['translated_attributes']));
        $analysis['slug_sources_normal']     = array_values(array_intersect($slugSources, $model['normal_attributes']));

        if ($analysis['translated'] === true) {
            $analysis['slug_sources_normal'] = [];
        } elseif ($analysis === false) {
            $analysis['slug_sources_translated'] = [];
        }


        // any matches? return as candidate
        if (    ! empty($analysis['slug_column'])
            ||  count($analysis['slug_sources_normal'])
            ||  count($analysis['slug_sources_translated'])
        ) {
            return $analysis;
        }

        return false;
    }
protected function analyzeModelForSluggable(array $model)
    {
        $analysis = [
            'translated'              => null,
            'slug_column'             => null,
            'slug_sources_normal'     => [],
            'slug_sources_translated' => [],
        ];

        // find out whether the model has a 'slug' column, preferring the first match we find
        $slugColumns = config('pxlcms.generator.models.slugs.slug_columns', []);

        foreach ($slugColumns as $slugColumn) {

            foreach ($model['normal_attributes'] as $attribute) {
                if ($attribute == $slugColumn) {
                    $analysis['slug_column'] = $attribute;
                    $analysis['translated']  = false;
                    break 2;
                }
            }

            foreach ($model['translated_attributes'] as $attribute) {
                if ($attribute == $slugColumn) {
                    $analysis['slug_column'] = $attribute;
                    $analysis['translated']  = true;
                    break 2;
                }
            }
        }

        // discard any matches that don't have a slug column on the model
        // if there is no slug structure present (because that could never work)
        if ( ! $this->context->slugStructurePresent && empty($analysis['slug_column'])) return false;

        // find out whether the model has slug source candidate columns
        $slugSources = config('pxlcms.generator.models.slugs.slug_source_columns', []);

        // make sure we keep slug and source column in the same model (translated or parent)
        $analysis['slug_sources_translated'] = array_values(array_intersect($slugSources, $model['translated_attributes']));
        $analysis['slug_sources_normal']     = array_values(array_intersect($slugSources, $model['normal_attributes']));

        if ($analysis['translated'] === true) {
            $analysis['slug_sources_normal'] = [];
        } elseif ($analysis === false) {
            $analysis['slug_sources_translated'] = [];
        }


        // any matches? return as candidate
        if (    ! empty($analysis['slug_column'])
            ||  count($analysis['slug_sources_normal'])
            ||  count($analysis['slug_sources_translated'])
        ) {
            return $analysis;
        }

        return false;
    }
protected function analyzeModelForSluggable ( array $ model ) { $ analysis = [ 'translated' => null , 'slug_column' => null , 'slug_sources_normal' => [ ] , 'slug_sources_translated' => [ ] , ] ; // find out whether the model has a 'slug' column, preferring the first match we find $ slugColumns = config ( 'pxlcms.generator.models.slugs.slug_columns' , [ ] ) ; foreach ( $ slugColumns as $ slugColumn ) { foreach ( $ model [ 'normal_attributes' ] as $ attribute ) { if ( $ attribute == $ slugColumn ) { $ analysis [ 'slug_column' ] = $ attribute ; $ analysis [ 'translated' ] = false ; break 2 ; } } foreach ( $ model [ 'translated_attributes' ] as $ attribute ) { if ( $ attribute == $ slugColumn ) { $ analysis [ 'slug_column' ] = $ attribute ; $ analysis [ 'translated' ] = true ; break 2 ; } } } // discard any matches that don't have a slug column on the model // if there is no slug structure present (because that could never work) if ( ! $ this -> context -> slugStructurePresent && empty ( $ analysis [ 'slug_column' ] ) ) return false ; // find out whether the model has slug source candidate columns $ slugSources = config ( 'pxlcms.generator.models.slugs.slug_source_columns' , [ ] ) ; // make sure we keep slug and source column in the same model (translated or parent) $ analysis [ 'slug_sources_translated' ] = array_values ( array_intersect ( $ slugSources , $ model [ 'translated_attributes' ] ) ) ; $ analysis [ 'slug_sources_normal' ] = array_values ( array_intersect ( $ slugSources , $ model [ 'normal_attributes' ] ) ) ; if ( $ analysis [ 'translated' ] === true ) { $ analysis [ 'slug_sources_normal' ] = [ ] ; } elseif ( $ analysis === false ) { $ analysis [ 'slug_sources_translated' ] = [ ] ; } // any matches? return as candidate if ( ! empty ( $ analysis [ 'slug_column' ] ) || count ( $ analysis [ 'slug_sources_normal' ] ) || count ( $ analysis [ 'slug_sources_translated' ] ) ) { return $ analysis ; } return false ; }
Determines whether the model data makes it a sluggable candidate
and returns analysis result

@param array $model  model data
@return array|false      false if not a candidate
Determines whether the model data makes it a sluggable candidate and returns analysis result