-
-
Notifications
You must be signed in to change notification settings - Fork 188
Slug is not updating (translatable slug) #235
-
Package v3.4.0
Laravel v9
Model slug definition:
use HasTranslations, HasTranslatableSlug;
public $translatable = [
'name',
'slug',
];
return SlugOptions::create()
->generateSlugsFrom(['name', 'starts_at_iso'])
->saveSlugsTo('slug');
It works only on create and it can't be updated with none of provided solutions:
$event->update(['name' => 'New name']); // Not working, slug is not updated
$event->name = 'foo'; // Not working
$event->save();
// Not working, slugs are still the old ones
$event->name = [
'en' => 'New name EN',
'hr' => 'New name HR',
];
$event->save();
$event->generateSlug(); // Not working
$event->save();
Slug update only works if I directly update the slug, but for this kind of code I don't even need any package.
$event->slug = 'foo'; // Only this works
$event->save();
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 3 comments 2 replies
-
The tests prove that this package is working as intended. Could you check the tests? If there's something not working, PR a failing test for us to fix.
Beta Was this translation helpful? Give feedback.
All reactions
-
I didn't make PR, but I realized it doesn't only update when I generate slug from multiple parameters.
generateSlugsFrom(['name']) // Works on update
generateSlugsFrom(['name', 'starts_at_iso']) // starts_at_iso is accessor, slug stays same on update
generateSlugsFrom(['name', 'country_code']) // country_code is column in DB, slug stays same on update
This is my method for slug generation:
public function getSlugOptions(): SlugOptions
{
return SlugOptions::create()
->generateSlugsFrom(['name', 'starts_at_iso'])
->saveSlugsTo('slug');
}
Beta Was this translation helpful? Give feedback.
All reactions
-
same thing happening with my code
Beta Was this translation helpful? Give feedback.
All reactions
-
Same problem
Beta Was this translation helpful? Give feedback.
All reactions
-
Same here. Here's a test that triggers the problem. I don't know whether it's intended behaviour or not but setting the slug manually once blocks subsequent automatic updates:
it('can update slugs', function () {
app()->setLocale('en');
$model1 = new TranslatableModel();
$model1->name = "Test Value";
$model1->save();
expect($model1->slug)->toBe('test-value');
app()->setLocale('de');
$model1->name = "Test Wert";
$model1->save();
expect($model1->slug)->toBe('test-wert');
app()->setLocale('en');
$model1->slug = "another-test-value";
$model1->save();
$model1->name = "New Test Value";
$model1->save();
expect($model1->slug)->toBe('new-test-value');
});
Beta Was this translation helpful? Give feedback.
All reactions
-
👀 1