Create slug

This commit is contained in:
2024-10-01 16:00:14 +03:00
parent 160c381abc
commit 5944dac053
3 changed files with 14 additions and 8 deletions

View File

@ -2,6 +2,7 @@
namespace kernel\helpers;
use Illuminate\Database\Eloquent\Model;
use kernel\FormModel;
use kernel\modules\post\models\Post;
@ -126,7 +127,17 @@ class Slug
return $options['lowercase'] ? mb_strtolower($str, 'UTF-8') : $str;
}
public static function recursiveCreateSlug($model, $slug, $tmpSlug = '', $id = 1): string
public static function createSlug(string $title, $model = null): string
{
$slug = Slug::url_slug($title, ['transliterate' => true, 'lowercase' => true]);
if ($model === null) {
return $slug;
}
return Slug::recursiveCreateSlug($model, $slug);
}
protected static function recursiveCreateSlug($model, string $slug, string $tmpSlug = '', int $id = 1): string
{
if ($tmpSlug === '') $tmpSlug = $slug;
if ($model::where(['slug' => $tmpSlug])->exists()) {