From 4118b803454e10bef6311649436d3e4b98743c90 Mon Sep 17 00:00:00 2001 From: Moamen Eltouny <16774083+MoamenEltouny@users.noreply.github.com> Date: Tue, 22 Feb 2022 11:43:24 +0200 Subject: [PATCH] support translatable --- src/Sluggable.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Sluggable.php b/src/Sluggable.php index d3da0c2..81c7eb2 100644 --- a/src/Sluggable.php +++ b/src/Sluggable.php @@ -52,6 +52,16 @@ protected static function bootSluggable() */ public function getSlugWithKeyAttribute() { + $isTranslatable = substr(__CLASS__, -11) == 'Translation'; + $class = substr(__CLASS__, 0, -11); + + if ($isTranslatable && class_exists($class)) { + $relation = strtolower(class_basename($class)); + if (method_exists($this, $relation)) { + return implode('-', [$this->{$relation}->getKey(), $this->slug]); + } + } + return implode('-', [$this->getKey(), $this->slug]); }