Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to create slug from title or slug field #272

Closed
vinacms opened this issue Jun 8, 2016 · 2 comments
Closed

How to create slug from title or slug field #272

vinacms opened this issue Jun 8, 2016 · 2 comments

Comments

@vinacms
Copy link

vinacms commented Jun 8, 2016

Hello,

I want automatic create slug from title or slug field. How to config it?

@shadoWalker89
Copy link

Well you can do this, as i did

public function sluggable()
    {
        return [
            'slug' => [
                'source' => ! empty($this->slug) ? 'slug' : 'title'
            ]
        ];
    }

But the problem is that the package doesn't support having the source and destination field the same.
I actually opened an issue about this #270

@cviebrock
Copy link
Owner

cviebrock commented Jun 8, 2016

Again, I'm not sure why you want to create a slug from a slug field. If you did source=>title, then it would store the generated slug in the slug field. If you save the model again (changing some other attribute), then the slug field will remain the same.

The package won't slug a model if the destination attribute has a value. This is to prevent slugs from constantly being calculated (and possibly overwritten) in cases where they shouldn't be. You don't want your post URLs changing randomly, right? ;)

If you want to regenerated a slug field from the source, set $model->slug = null before saving.

See #270 for more discussion on source and dest fields being the same. I'm still not convinced this is a use-case for the package (but I'm happy to review a PR that adds that functionality).

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

No branches or pull requests

3 participants