Skip to content

Commit

Permalink
unique validator with targetClass so in works for translations
Browse files Browse the repository at this point in the history
  • Loading branch information
eluhr committed Jan 4, 2024
1 parent 8850223 commit 3eff8bd
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/generators/model/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 3eff8bd

Please sign in to comment.