nova-sluggable
nova-sluggable copied to clipboard
Generate Button
Hi there,
Would it be possible to add an option where the slug is generated by clicking a button instead of keyup and blur? I'd only like to generate the slug if it's required. As is, the slug will change when the title field is updated. I don't really want the slug automatically change if I'm editing vs. creating.
Thanks!
@cgarofalo Only if I understood it correctly.
You could distinguish update and create with the given $request
and readonly
method.
Slug::make(...)->readOnly($request->isUpdateOrUpdateAttachedRequest() ? true : false)
This will prevent the slug from being changed in edit mode and the slug being changable in any other mode.
@cgarofalo Ah sorry, this behaviour isn't cross-browser. I create a new issue and PR if the author is ok with an added feature.
That would make the package much more usable. Slug are often in URL segments and these shouldn't accidentally change - for a number of reasons (SEO, bookmarks, etc.).
Do you think you could look at this @drobee ?
As a workaround to prevent changes on update, you could do it like so:
SluggableText::make()
->slug($request->isUpdateOrUpdateAttachedRequest() ? 'DONOTUPDATE' : 'Slug');
It checks if its an update request and if yes, it tries to update the not existing 'DONOTUPDATE' field. Otherwise (on create) it uses the correct field label Slug
(or whatever you named it).
This is dirty, I know, but it works until @drobee fixes this issue.
That's a good idea. Thanks for the suggestion @bernhardh