cviebrock / eloquent-sluggable

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

how to doesn't consider GlobalScope when slug is creating? #572

Closed Parvaz19 closed 2 years ago

Parvaz19 commented 2 years ago

Hi, at first thanks for this awesome package.

posts table has is_active column that I define GlobalScope for return only records with is_active=true. for all posts must create slug.

assume a post has slug='how-are-you' and is_active=false. when I want to create a new post with title='how are you' the slug

will equal to 'how-are-you'. I want to use unique slug so I set unique=true in sluggable config file. but cause GlobalScope is set,

Sluggable doesnt consider a record that has similar slug and create a duplicate slug and mysql has error because slug field is

defind as unique. how to handle this problem that Sluggable doesn't consider GlobalScope?

thanks a lot.

Parvaz19 commented 2 years ago

I'm sorry. this issue is duplicate. according to #521 I use

public function scopeWithUniqueSlugConstraints(Builder $query, Model $model, $attribute, $config, $slug) { return $query->withoutGlobalScope(MyScope::class); }

in Post model and my problem is solved.

thak you @cviebrock