Laravel String Helper Function: camel

November 16, 2016 —John Koster

Camel casing is similar to studly case such that each word starts with a capitalized letter, with the difference being the first character is lower cased. Like the studly method, the camel method will not affect the casing of the rest of the word.

The signature of the camel helper function is:

camel($value)

The following examples will all return the string myWords:

1use Illuminate\Support\Str;
2 
3// myWords
4echo Str::camel('my words');
5 
6// myWords
7echo Str::camel('my-words');
8 
9// myWords
10echo Str::camel('my_words');
11 
12// myWords
13echo Str::camel(' my-words_');

Again, the camel function does not affect the casing of any characters after the first one.

1use Illuminate\Support\Str;
2 
3// mYWORDS
4echo Str::camel('MY WORDS');
5 
6// mywords
7echo Str::camel('mywords');

#camel_case($value)

The camel_case function is a shortcut to calling Str::camel. This function is declared in the global namespace.

Some absolutely amazing
people

The following amazing people help support this site and my open source projects ♥️
If you're interesting in supporting my work and want to show up on this list, check out my GitHub Sponsors Profile.