@@ -124,10 +124,10 @@ public function restoreSlugs(): void
124
124
*/
125
125
public function handleSlugsOnSave (): void
126
126
{
127
- $ this ->disableLocaleSlugs ();
128
-
129
127
$ slugParams = $ this ->twillSlugData !== [] ? $ this ->twillSlugData : $ this ->getSlugParams ();
130
128
129
+ $ this ->disableLocaleSlugs ();
130
+
131
131
foreach ($ slugParams as $ params ) {
132
132
if (in_array ($ params ['locale ' ], config ('twill.slug_utf8_languages ' , []))) {
133
133
$ params ['slug ' ] = $ this ->getUtf8Slug ($ params ['slug ' ]);
@@ -358,9 +358,13 @@ public function getSlugParams(?string $locale = null): ?array
358
358
throw new \Exception ("You must define the field {$ slugAttribute } in your model " );
359
359
}
360
360
361
+ $ slug = $ this ->getSlugValue ($ slugAttribute , $ translation ->locale )
362
+ ?? $ translation ->$ slugAttribute
363
+ ?? $ this ->$ slugAttribute ;
364
+
361
365
$ slugParam = [
362
366
'active ' => $ translation ->active ?? true ,
363
- 'slug ' => $ translation -> $ slugAttribute ?? $ this -> $ slugAttribute ,
367
+ 'slug ' => $ slug ,
364
368
'locale ' => $ translation ->locale ,
365
369
] + $ slugDependenciesAttributes ;
366
370
@@ -400,7 +404,7 @@ public function getSingleSlugParams(?string $locale = null): ?array
400
404
401
405
$ slugParam = [
402
406
'active ' => 1 ,
403
- 'slug ' => $ this ->$ slugAttribute ,
407
+ 'slug ' => $ this ->getSlugValue ( $ slugAttribute , $ appLocale ) ?? $ this -> $ slugAttribute ,
404
408
'locale ' => $ appLocale ,
405
409
] + $ slugDependenciesAttributes ;
406
410
@@ -415,6 +419,21 @@ public function getSingleSlugParams(?string $locale = null): ?array
415
419
return $ locale === null ? $ slugParams : null ;
416
420
}
417
421
422
+ /**
423
+ * Returns changed value of slugAttribute field or previous slug value
424
+ *
425
+ * @param $slugAttribute
426
+ * @param $locale
427
+ * @return mixed|null
428
+ */
429
+ private function getSlugValue ($ slugAttribute , $ locale ): mixed
430
+ {
431
+ return $ this ->wasChanged ($ slugAttribute )
432
+ ? $ this ->$ slugAttribute
433
+ : $ this ->slugs ()->where ('locale ' , $ locale )
434
+ ->where ('active ' , true )->value ('slug ' );
435
+ }
436
+
418
437
/**
419
438
* Returns the database table name for this model's slugs.
420
439
*/
0 commit comments