Working with strings can prove to be tricky in some scenarios. For instance, when building a cart for an eCommerce website, you may need to show the string “item” in singular/plural form based on how many items are there in the cart. You may resort to using it like so and be done with it.

So, if we want to display the string “item” in singular/plural based on the item count, here’s how we can do it using the plural helper method. use Illuminate\Support\Str; $itemCount = 1; $cartItems = Str::of('item')->plural($itemCount); // item $itemCount = 5; $cartItems = Str::of('item')->plural($itemCount); // items
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future. Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future.
Community Partners