Проверка slug на уникальность
@param Model $model
@param string $slug
@return bool
332632
private function validateUnique($model, $slug)
    {
        $slug = trim(trim($slug, '/'));
        /* @var $model ActiveRecord */
        $query = SeoSlug::find()
            ->where(['=', 'slug', $slug]);
        if ($model->isNewRecord === false) {
            $query->andWhere([
                'OR',
                [
                    'AND',
                    ['!=', 'model', $model::className()],
                    ['=', 'model_id', $model->getPrimaryKey()],
                ],
                ['!=', 'model_id', $model->getPrimaryKey()],
            ]);
        }
        return $query->count() < 1;
    }
184445
protected function setHeaderFieldModel($field, $model)
    {
        if ($this->headers->has($field)) {
            $this->headers->get($field)->setFieldBodyModel($model);

            return true;
        }

        return false;
    }
454645
protected function setSlug($model)
    {
        if ($this->isSluggable($model)) {
            $model->slug = str_slug($model->{$model::$slug['name']});

            try {
                $latestSlug = $model->whereRaw("slug RLIKE '^{$model->{$model::$slug['field']}}(-[0-9]*)?$'")
                    ->latest('id')
                    ->value('slug');
            } catch (\Illuminate\Database\QueryException $e) {
                $latestSlug = $model->whereRaw("slug LIKE '^{$model->{$model::$slug['field']}}(-[0-9]*)?$'")
                    ->latest('id')
                    ->value('slug');
            }

            if ($latestSlug) {
                $pieces = explode('-', $latestSlug);
                $number = intval(end($pieces));
                $model->{$model::$slug['field']} .= '-'.($number + 1);
            }
        }
    }
133523
public function doesSlugAlreadyExist($slug)
    {
        $rowCount = DB::table($this->model->table)
            ->where('slug',  $slug)
            ->count();

        if ($rowCount > 0) return $rowCount;
        return 0;
    }
387669
public function isManuallyChangedSlugInEditForm($slug, $id=false)
    {
        // If there is no $id, then there's nothing to figure out!
        if (!$id) return false;

        $record = DB::table($this->model->table)
            ->where('id', $id)
            ->first()
        ;

        if ($record->slug == $slug) {

            // The slug entered into the form is the same slug that is already in the database, so no change...
            return false;

        } else {

            // The slug entered into the form is different than the slug in the database, so yes it has changed...
            return true;
        }
    }
644724
public function beforeDelete(Model $Model, $cascade = true) {
		if ($this->settings[$Model->alias]['auto'] === false) {
			return true;
		}
		if (!$Model->ShadowModel) {
			return true;
		}
		foreach ($Model->hasAndBelongsToMany as $assocAlias => $a) {
			if (isset($Model->{$assocAlias}->ShadowModel->_schema[$Model->alias])) {
				$joins = $Model->{$a['with']}->find('all', array('recursive' => -1, 'conditions' => array($a['foreignKey'] => $Model->
							id)));
				$this->deleteUpdates[$Model->alias][$assocAlias] = Hash::extract($joins, '{n}.' . $a['with'] . '.' . $a['associationForeignKey']);
			}
		}
		return true;
	}
293595
public function creating(Page $model)
    {
        $slugs = $model->getTranslations('slug');
        foreach ($slugs as $locale => $slug) {
            $uri = $this->incrementWhileExists($model, $slug, $locale);
            $model->setTranslation('uri', $locale, $uri);
        }
    }
369488
protected function shouldCommit(Model $model)
    {
        $state = $model->getState();
        return $model->isDirty() || $state->is('new') || $state->is('deleting');
    }
389582
public static function findBySlug($slug)
    {
        $video = Video::find()
            ->with(['images' => function ($imageQuery) {
                $imageQuery->select(['image_id', 'video_id', 'filepath', 'source_url'])
                    ->indexBy('image_id');
            }])
            ->with(['categories' => function ($categoryQuery) {
                $categoryQuery->select(['category_id', 'title', 'slug', 'h1'])
                	->where(['enabled' => 1]);
            }])
            ->where(['slug' => $slug, 'status' => VideoStatus::PUBLISH])
            ->asArray()
            ->one();

            // постер для видео
        if (null !== $video && !empty($video['images'][$video['image_id']])) {
            $video['image'] = $video['images'][$video['image_id']];
        }

        return $video;
    }
452226
protected function isColumnTranslated(Model $model, $column)
    {
        $info = $this->getModelInformation($model);

        if ($info) {
            return (    $info->translated
                    &&  array_key_exists($column, $info->attributes)
                    &&  $info->attributes[$column]->translated
                    );
        }

        // Determine based on model itself
        if ( ! $this->hasTranslatableTrait($model)) return false;

        /** @var Translatable $model */
        return $model->isTranslationAttribute($column);
    }
1251128
public function setHrefLangData($model, $routeName = '')
    {
        foreach(Language::getVisibleList() as $language){
            Meta::setHrefLang($model->translate($language->slug)->href($routeName), $language->slug);
        }
        return $this;
    }
3335
private function doCommitCreate(Model $model)
    {
        $this->dispatchLifecycleEvent(Events::preCreate, $model);

        $this->getPersisterFor($model->getType())->create($model);
        $model->getState()->setNew(false);
        // Should the model always reload? Or should the commit be assumed correct and just clear the new/dirty state?
        $model->reload();

        $this->dispatchLifecycleEvent(Events::postCreate, $model);
        return $model;
    }
1027954
protected function fireSluggingEvent(Model $model, string $event)
    {
        return $this->events->until('eloquent.slugging: ' . get_class($model), [$model, $event]);
    }
188783
public function save(Model $model)
    {
        $this->setForeignAttributesForCreate($model);

        return $model->save() ? $model : false;
    }
256793
private function getAction(Model $Model)
	{
		$isCreate = true;
		$id = null;

		if (isset($Model->data[$Model->alias][$Model->primaryKey]) && !empty($Model->data[$Model->alias][$Model->primaryKey])) {
			$id = $Model->data[$Model->alias][$Model->primaryKey];
		}
		elseif (!empty($Model->id)) {
			$id = $Model->id;
		}

		if (!empty($id)) {
			$isCreate = !$Model->exists($id);
		}

		return $isCreate ? 'create' : 'modify';
	}
1129534
public function clearCache(Model $model) {
        if ($this->_cached) {
            foreach ($this->_cached as $key => $value) {
                $this->deleteCache($model, $key);
            }
        }

        return Cache::clear(false, $this->settings[$model->alias]['cacheConfig']);
    }
484989
protected function checkPermission(User $user, $model, $action)
    {
        $regex = str_replace('/', '\/', preg_quote(route('admin.dashboard')));
        $slug = preg_replace('/'.$regex.'/', '', $model->link(true));
        $slug = str_replace('/', '', explode('/', ltrim($slug, '/'))[0]);

        if (!isset(self::$datatypes[$slug])) {
            self::$datatypes[$slug] = DataType::where('slug', $slug)->first();
        }

        if ($str = self::$datatypes[$slug]) {
            $slug = $str->slug;
        }

        if ($slug == '') {
            $slug = 'admin';
        }

        // If permission doesn't exist, we can't check it!
        if (!Admin::model('Permission')->where('key', 'browse_'.$slug)->exists()) {
            return true;
        }

        return $user->hasPermission('browse_'.$slug);
    }