fix create slug
This commit is contained in:
@ -2,6 +2,9 @@
|
||||
|
||||
namespace kernel\helpers;
|
||||
|
||||
use kernel\FormModel;
|
||||
use kernel\modules\post\models\Post;
|
||||
|
||||
class Slug
|
||||
{
|
||||
|
||||
@ -123,6 +126,15 @@ class Slug
|
||||
return $options['lowercase'] ? mb_strtolower($str, 'UTF-8') : $str;
|
||||
}
|
||||
|
||||
public static function recursiveCreateSlug($model, $slug, $tmpSlug = '', $id = 1): string
|
||||
{
|
||||
if ($tmpSlug === '') $tmpSlug = $slug;
|
||||
if ($model::where(['slug' => $tmpSlug])->exists()) {
|
||||
$tmpSlug = $slug . '-' . $id++;
|
||||
$tmpSlug = Slug::recursiveCreateSlug($model, $slug, $id);
|
||||
}
|
||||
return $tmpSlug;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -162,4 +174,5 @@ chto-delat-esli-ya-ne-hochu-utf-8
|
||||
××-××-×× ×-××-ר×צ×-utf-8-ת××××
|
||||
This is an Example String. What's Going to Happen to Me?
|
||||
This_is_a_Test_String_What_s_Going_to_Ha
|
||||
*/
|
||||
*/
|
||||
|
||||
|
Reference in New Issue
Block a user