Conditions | 5 |
Paths | 4 |
Total Lines | 24 |
Code Lines | 16 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
39 | protected function addUniqueValidation() |
||
40 | { |
||
41 | if (count((array) $this->unique) > 0) { |
||
42 | $pairs = []; |
||
43 | $parameters = array_unique(array_merge([ |
||
44 | $mainKey = $this->getModel()->getForeignKey(), |
||
|
|||
45 | ], $this->unique)); |
||
46 | |||
47 | $errorColumns = array_filter($parameters, function ($param) use ($mainKey) { |
||
48 | return $param !== $mainKey; |
||
49 | }); |
||
50 | |||
51 | $relations = (array) request($this->relationName); |
||
52 | |||
53 | foreach ($relations as $index => $relation) { |
||
54 | $relation[$mainKey] = $this->getModel()->getKey(); |
||
55 | $key = $this->getCompositeKey($relation, (array) $parameters); |
||
56 | |||
57 | if (array_key_exists($key, $pairs)) { |
||
58 | foreach ($errorColumns as $column) { |
||
59 | $this->validationRules[$this->relationName.'.'.$index.'.'.$column] = 'unique_related'; |
||
60 | } |
||
61 | } else { |
||
62 | $pairs[$key] = true; |
||
63 | } |
||
68 |