From 3eff8bdd10af52a41a6fea6bf48676f1ad3fdcf1 Mon Sep 17 00:00:00 2001 From: Elias Luhr Date: Thu, 4 Jan 2024 16:23:57 +0100 Subject: [PATCH] unique validator with targetClass so in works for translations --- src/generators/model/Generator.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/generators/model/Generator.php b/src/generators/model/Generator.php index 5e91133..8daec01 100644 --- a/src/generators/model/Generator.php +++ b/src/generators/model/Generator.php @@ -632,8 +632,22 @@ public function generateRules($table) $ns = "\\{$this->ns}\\"; $match = "'targetClass' => "; $replace = $match . $ns; + + + $replaceMap = [ + [ + 'search' => "'targetClass' => ", + 'replace' => "'targetClass' => " . $ns, + ], + [ + 'search' => "'unique', ", + 'replace' => "'unique', 'targetClass' => " . $ns . $this->modelClass . '::class, ', + ] + ]; foreach ($parentRules as $k => $parentRule) { - $parentRules[$k] = str_replace($match, $replace, $parentRule); + foreach ($replaceMap as $replaceItem) { + $parentRules[$k] = str_replace($replaceItem['search'], $replaceItem['replace'], $parentRule); + } } $rules = array_merge($parentRules, $rules);