This commit is contained in:
Билай Станислав 2024-10-07 11:29:56 +03:00
parent 5944dac053
commit a26eeb9441

View File

@ -127,6 +127,11 @@ class Slug
return $options['lowercase'] ? mb_strtolower($str, 'UTF-8') : $str; return $options['lowercase'] ? mb_strtolower($str, 'UTF-8') : $str;
} }
/**
* @param string $title
* @param $model
* @return string
*/
public static function createSlug(string $title, $model = null): string public static function createSlug(string $title, $model = null): string
{ {
$slug = Slug::url_slug($title, ['transliterate' => true, 'lowercase' => true]); $slug = Slug::url_slug($title, ['transliterate' => true, 'lowercase' => true]);
@ -137,7 +142,14 @@ class Slug
return Slug::recursiveCreateSlug($model, $slug); return Slug::recursiveCreateSlug($model, $slug);
} }
protected static function recursiveCreateSlug($model, string $slug, string $tmpSlug = '', int $id = 1): string /**
* @param $model
* @param string $slug
* @param string $tmpSlug
* @param int $id
* @return string
*/
private static function recursiveCreateSlug($model, string $slug, string $tmpSlug = '', int $id = 1): string
{ {
if ($tmpSlug === '') $tmpSlug = $slug; if ($tmpSlug === '') $tmpSlug = $slug;
if ($model::where(['slug' => $tmpSlug])->exists()) { if ($model::where(['slug' => $tmpSlug])->exists()) {