doNotGenerateSlugsOnUpdate()
angelinek opened this issue · 1 comments
angelinek commented
Hi,
I hope that my slug will not be updated when I updated my name
Is that possible?
I have tried to include the code below, but it doesnt work
public function getSlugOptions() : SlugOptions
{
return SlugOptions::create()
->generateSlugsFrom('name')
->saveSlugsTo('slug')
->doNotGenerateSlugsOnUpdate();
}
mmanzano commented
you can do a work around with this:
$isUpdateOrUpdateAttachedRequest = $request->isUpdateOrUpdateAttachedRequest();
$slugField = $isUpdateOrUpdateAttachedRequest ? 'Not A Slug' : 'Slug';
return [
ID::make()->sortable(),
SluggableText::make('Name')
->slug($slugField)
->sortable()
->rules('required', 'max:255'),
Slug::make('Slug', 'slug')
->slugUnique()
->slugModel(static::$model)
->rules('required', 'max:255')
->readonly($isUpdateOrUpdateAttachedRequest),
];