Skip to content

retrieve slug from slugs table if the $slugAttribute field was not changed#2688

Open
zeezo887 wants to merge 1 commit into
area17:3.xfrom
zeezo887:fix/slug-with-suffix-gets-duplicated-on-model-save
Open

retrieve slug from slugs table if the $slugAttribute field was not changed#2688
zeezo887 wants to merge 1 commit into
area17:3.xfrom
zeezo887:fix/slug-with-suffix-gets-duplicated-on-model-save

Conversation

@zeezo887

@zeezo887 zeezo887 commented Nov 1, 2024

Copy link
Copy Markdown
Collaborator

Description

The changes made here was to use the previous slug value if the $slugAttribute field was not changed. By doing this, we won't have duplicate slug entries when a model is not updated via the repository.

/**
 * Returns changed value of slugAttribute field or previous slug value
 */
private function getSlugValue($slugAttribute, $locale): mixed
{
    return $this->wasChanged($slugAttribute)
        ? $this->$slugAttribute
        : $this->slugs()->where('locale', $locale)
            ->where('active', true)->value('slug');
}

Related Issues

Fixes #2681

@Tofandel

Tofandel commented Nov 19, 2024

Copy link
Copy Markdown
Contributor

Is the disableLocaleSlug even needed before? This seems to be done already in updateOrNewSlug and I'm sure it's interfering with getOldSlug->active

*/
private function getSlugValue($slugAttribute, $locale): mixed
{
return $this->wasChanged($slugAttribute)

@Tofandel Tofandel Nov 19, 2024

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fix doesn't work for slugs from translations, because then translations are never detected as changed and it will return the slug before change

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

All module slugs get reset on reorder.

2 participants