Skip to content

Commit 3a4a4dd

Browse files
committed
Add option to trim leading & trailing whitespace.
1 parent 7914de6 commit 3a4a4dd

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

config/unique_names.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,14 @@
6565
|
6666
*/
6767
'with_trashed' => false,
68+
69+
/*
70+
|-----------------------------------------------------------------------------------------
71+
| Trim
72+
|-----------------------------------------------------------------------------------------
73+
|
74+
| Whether or not to trim leading & tailing whitespace.
75+
|
76+
*/
77+
'trim' => true,
6878
];

src/HasUniqueNames.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ public function getConstraintValues(array $constraintFields): array
6565
*/
6666
public function getUniqueValue(string $uniqueField, array $constraintFields, string $value, array $constraintValues, mixed $exclude_id = null): string
6767
{
68+
if (config('unique_names.trim', true)) {
69+
$uniqueField = trim($uniqueField);
70+
}
71+
6872
// First, check if the original value is unique
6973
$query = self::query();
7074
$query->when($this->_uniqueIncludesTrashed, fn ($query) => $query->withTrashed());

0 commit comments

Comments
 (0)