src/Sluggable/SluggableTrait.php
public function scopeWhereSlug($scope, $slug, $locale = null, $forHasQuery = false)
    {
        /** @var CmsModel|SluggableTrait $model */
        $model = new static;

        if ($model->storeSlugLocally()) {
            return $this->CviebrockScopeWhereSlug($scope, $slug);
        }

        // build scope with join to slugs table ..
        $scope = $scope->join(
            static::$slugsTable,
            function($join) use ($model, $locale) {

                $idKey = $this->isTranslationModel()
                    ?   config('pxlcms.translatable.translation_foreign_key')
                    :   $this->getKeyName();

                $join->on($model->getTable() . '.' . $idKey, '=', static::$slugsTable . '.' . static::$slugsEntryKey);
                $join->on(static::$slugsTable . '.' . static::$slugsModuleKey, '=', DB::raw( (int) $model->getModuleNumber()));

                if ( ! empty($locale) && $model->isTranslationModel()) {
                    $languageId = $model->lookUpLanguageIdForLocale($locale);

                    $join->on(static::$slugsTable . '.' . static::$slugsLanguageKey, '=', DB::raw( (int) $languageId));
                }
            }
        );

        return $scope->where(static::$slugsTable . '.' . static::$slugsColumn, $slug)
                     ->select($this->getTable() . '.' . ($forHasQuery ? 'id' : '*'));
    }
public function scopeWhereSlug($scope, $slug, $locale = null, $forHasQuery = false)
    {
        /** @var CmsModel|SluggableTrait $model */
        $model = new static;

        if ($model->storeSlugLocally()) {
            return $this->CviebrockScopeWhereSlug($scope, $slug);
        }

        // build scope with join to slugs table ..
        $scope = $scope->join(
            static::$slugsTable,
            function($join) use ($model, $locale) {

                $idKey = $this->isTranslationModel()
                    ?   config('pxlcms.translatable.translation_foreign_key')
                    :   $this->getKeyName();

                $join->on($model->getTable() . '.' . $idKey, '=', static::$slugsTable . '.' . static::$slugsEntryKey);
                $join->on(static::$slugsTable . '.' . static::$slugsModuleKey, '=', DB::raw( (int) $model->getModuleNumber()));

                if ( ! empty($locale) && $model->isTranslationModel()) {
                    $languageId = $model->lookUpLanguageIdForLocale($locale);

                    $join->on(static::$slugsTable . '.' . static::$slugsLanguageKey, '=', DB::raw( (int) $languageId));
                }
            }
        );

        return $scope->where(static::$slugsTable . '.' . static::$slugsColumn, $slug)
                     ->select($this->getTable() . '.' . ($forHasQuery ? 'id' : '*'));
    }
public function scopeWhereSlug ( $ scope , $ slug , $ locale = null , $ forHasQuery = false ) { /** @var CmsModel|SluggableTrait $model */ $ model = new static ; if ( $ model -> storeSlugLocally ( ) ) { return $ this -> CviebrockScopeWhereSlug ( $ scope , $ slug ) ; } // build scope with join to slugs table .. $ scope = $ scope -> join ( static :: $ slugsTable , function ( $ join ) use ( $ model , $ locale ) { $ idKey = $ this -> isTranslationModel ( ) ? config ( 'pxlcms.translatable.translation_foreign_key' ) : $ this -> getKeyName ( ) ; $ join -> on ( $ model -> getTable ( ) . '.' . $ idKey , '=' , static :: $ slugsTable . '.' . static :: $ slugsEntryKey ) ; $ join -> on ( static :: $ slugsTable . '.' . static :: $ slugsModuleKey , '=' , DB :: raw ( ( int ) $ model -> getModuleNumber ( ) ) ) ; if ( ! empty ( $ locale ) && $ model -> isTranslationModel ( ) ) { $ languageId = $ model -> lookUpLanguageIdForLocale ( $ locale ) ; $ join -> on ( static :: $ slugsTable . '.' . static :: $ slugsLanguageKey , '=' , DB :: raw ( ( int ) $ languageId ) ) ; } } ) ; return $ scope -> where ( static :: $ slugsTable . '.' . static :: $ slugsColumn , $ slug ) -> select ( $ this -> getTable ( ) . '.' . ( $ forHasQuery ? 'id' : '*' ) ) ; }
Query scope for finding a model by its slug.

@param Builder $scope
@param string  $slug
@param string  $locale       if not set, matches for any locale
@param bool    $forHasQuery  if true, the scope is part of a has relation subquery
@return mixed
Query scope for finding a model by its slug .