tomhatzer / nova-slug-field

Slug field for Laravel Nova
MIT License
142 stars 27 forks source link

Custom slug function #4

Closed stevelacey closed 4 years ago

stevelacey commented 6 years ago

Would be great to be able to customize the slug function used, in the Nova resource, ideally

benjaminhirsch commented 6 years ago

If you mean setting attributes, then you will be able to set these with the latest release. See PR: https://github.com/benjaminhirsch/nova-slug-field/pull/5 😄

beausif commented 6 years ago

I'm guessing he is referencing how the slug is created. Ability to pass a delimiter shouldn't be too hard to implement. Although the ability to actually override the default method call would be preferable, although I'm not sure how that would be accomplished.

stevelacey commented 6 years ago

My use case is to use it for entirely different things that need the same “update another field based on this one” logic — but not necessarily with the same chars stripped and kebab-cased.

I read the source and it looks like at some point you considered using ajax to gen the slug, as there is some code left over from that, that could be an opt-in to get the logic into php land... but yeah, slow.

Something semi-janky like supplying a js function snippet in the resource that is pulled along with the field could also be an option... but yeah, bleurgh.

bernhardh commented 4 years ago

To change the separator just use:

Slug::make('Slug')
    ->slugifyOptions([
        "separator" => "_"
    ])

Or you can add any option of speakingurl: https://github.com/pid/speakingurl

tomhatzer commented 4 years ago

I can't find any code related to anything calling a backend method to create slugs. This is also be out of scope for this package, same as updating other fields with different values.

speakingurl is the js package that's currently being used to slugify the string, which is quite outdated (last update 3 years ago). If anyone is able to help, moving to https://github.com/simov/slugify might be a good choice. PRs are very welcome for this.

Until then I'm closing here.