cviebrock / eloquent-sluggable

Easy creation of slugs for your Eloquent models in Laravel
MIT License
3.91k stars 461 forks source link

how to ignore current slug for unique on SlugService::createSlug when update model #579

Closed nekooee closed 2 years ago

nekooee commented 2 years ago

Hi, I use the following code to set the slug: $slug = SlugService::createSlug(Article::class, 'slug', $request->input('slug'));

but when updating the model, a number is added to the slug. how to ignore the current slug for unique?

Thank you

vishal-gc commented 2 years ago

Hi, I use the following code to set the slug: $slug = SlugService::createSlug(Article::class, 'slug', $request->input('slug));

but when updating the model, a number is added to the slug. how to ignore the current slug for unique?

Thank you

Hi, I'm going through the same situation recently, I found the solution. When you updating your model just pass model instance of current article like this.

$article = Article::find($id); $slug = SlugService::createSlug($article, 'slug', $request->input('slug));