Skip to content

Conversation

caseydwyer
Copy link
Contributor

@caseydwyer caseydwyer commented Aug 27, 2025

When we reach for the Str::plural() helper, we frequently want to prepend the pluralized string with the $count itself. That typically looks something like this:

We had {{ number_format($attendees->count()) . ' ' . Str::plural('attendee', $attendees->count()) }} at Laracon 2025.

This PR cleans up the repetition a bit, by adding an optional prependCount parameter to the Str::plural() method. Here's what the above looks like, when using that option:

We had {{ Str::plural('attendee', $attendees->count(), prependCount: true) }} at Laracon 2025.

The parameter defaults to false, so a non-breaking change. Tests included, and added a couple of extras that I think are mostly covered by the Pluralizer...but thought it might be helpful to ensure we don't get any unexpected $count prepending when this new param is not in use, since the Pluralizer isn't aware of that piece. Let me know if there's anything I can change or help with, here! Happy to update docs as well, if this gets merged.

Edit: updated to reflect Taylor's formatting changes on parameter name

if `$prepend` is truthy, prepend the formatted `$count` and a space
included a couple that are mostly covered by the Pluralizer, but wanted to ensure we don't get unexpected prepended `$count` as the Pluralizer isn't aware of that piece
@taylorotwell taylorotwell merged commit b00bcee into laravel:12.x Aug 29, 2025
21 of 63 checks passed
@siarheipashkevich
Copy link
Contributor

@caseydwyer please add this information to the documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants