Laravel 5 String Helpers: Getting the Singular Form of a String Value

December 6, 2017 —John Koster

The singular helper method is the logical opposite to the plural method: it will attempt to take a given $value and return the singular form of that word. The internal mechanisms are similar to the plural method.

#Signature

The signature of the singular method is:

1public static function singular(
2 $value
3 );

#Example Use

1use Illuminate\Support\Str;
2 
3// cow
4echo Str::singular('cows');
5 
6// person
7echo Str::singular('people');
8 
9// curve
10echo Str::singular('curves');
11 
12// message
13echo Str::singular('messages');

#singular Special Cases

Any words, or word endings, in the following table will not be affected by the singular method. This is either because the resulting word is already singular, or because there is no inflection available. Word endings are denoted by the prefix *:

The following table lists the words that are not inflected by the singular method. This is either because the resulting word is already singular, or because there are no clear inflection rules available, or they handled separately (see the singular Special cases table).

Special Cases Special Cases Special Cases Special Cases
Amoyese bison Borghese bream
breeches britches buffalo cantus
carp chassis clippers code
caoitus Congoese contretemps corps
data debris diabetese djinn
eland elk equipment Faroese
flounder Foochowese Furniture gallows
Genevese Genoese Glibertese graffiti
headquarters herpes hijinks Hottentotese
information innings jackanapes Kiplingese
Kongoese Lucchese Luggage mackerel
Maltese *media mews moose
mumps Nankingese news nexus
Niasese Pekingese Piedmontese pincers
Postoiese pliers Portuguese proceedings
rabies rice rhinoceros salmon
Sarawakese scissors seabass sea-bass
series Shavese shears siemens
species staff swine testes
trousers trout tuna Vermontese
Wenchowese whitting wildebeest Yengeese

In addition to the general words that are not inflected by the singular method, the following tables list the word patterns or values that will also not be inflected by this method:

Words Not Inflected Words Not Inflected Words Not Inflected Words Not Inflected
*nese *rese *lese *mese
*deer *fish *measles *ois
*pox *sheep *ss data
police pants clothes

In addition to words that are not inflected, the method also handles some special cases. These are generally words that do not have a clear pragmatic method of handling the inflection of converting the word to its singular equivalent:

Plural Form Singular Form
atlases atlas
avalanches avalanche
axes axe
beefs beef
caches cache
cafes cafe
chateaux chateau
criteria criterion
niveaux niveau
children child
cookies cookie
corpuses corpus
cows cow
criteria criterion
curricula curriculum
curves curve
demos demo
dominos domino
echoes echo
emphases emphasis
feet foot
foes foe
fungi fungus
ganglions ganglion
genies genie
genera genus
graffiti graffito
graves grave
hippopotami hippopotamus
hoaxes hoax
hoofs hoof
humans human
irises iris
larvae larva
leaves leaf
loaves loaf
men man
media medium
memoranda memorandum
monies money
mongooses mongoose
mottoes motto
moves move
mythoi mythos
neuroses neurosis
niches niche
nuclei nucleus
numina numen
oases oasis
occiputs occiput
octopuses octopus
opuses opus
oxen ox
passersby passerby
penises penis
people person
plateaux plateau
runners-up runner-up
sexes sex
soliloquies soliloquy
sons-in-law son-in-law
syllabi syllabus
testes testis
thieves thief
teeth tooth
tornadoes tornado
trilbys trilby
turfs turf
waves wave
volcanoes volcano

#Global str_singular Helper Function

The str_singular function is a shortcut to calling Str::singular. 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.