nova-sluggable icon indicating copy to clipboard operation
nova-sluggable copied to clipboard

doNotGenerateSlugsOnUpdate()

Open angelinek opened this issue 4 years ago • 1 comments

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(); }

angelinek avatar Dec 23 '20 02:12 angelinek

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),
        ];

mmanzano avatar Jul 27 '21 12:07 mmanzano