Skip to content

Commit e739ec5

Browse files
committed
- Fixed slug to title to handle all upper and all lower case
1 parent 51a5e73 commit e739ec5

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/helpers.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -227,11 +227,11 @@ function remove_suffix($needle, $haystack): string
227227
function slug_to_title($slug, string $separator = '_'): string
228228
{
229229
return Str::of($slug)
230-
->camel()
231-
->snake($separator)
232-
->replace($separator, ' ')
233-
->title()
234-
->toString();;
230+
->replaceMatches('/([a-z])([A-Z])/', '$1 $2') // Split camelCase: pEnding → p Ending
231+
->replace($separator, ' ') // Replace custom separator (e.g. _ or space) with space
232+
->lower() // Lowercase everything
233+
->title() // Capitalize words
234+
->toString();
235235
}
236236
}
237237

0 commit comments

Comments
 (0)