Press "Enter" to skip to content

Conditional Pluralization in Laravel

Sharing is caring!

Laravel provides an easy string transformation helpers. Some of the most used helpers are starts_with, ends_with, str_contains, str_slug. At some point, we need some transformation helpers for string too.

Like plural and singular forms of string.

But that’s not it.

We can pass second arguments. If the second parameter is equal to 1 it will return the singular form without converting it. But if not, it will convert to its plural form.

Everything is awesome.

Be First to Comment

    Leave a Reply

    Your email address will not be published.