Skip to content

Conversation

caseydwyer
Copy link

When we reach for the Str::plural() helper, we frequently want to prepend the string itself with the $count that's being passed in. 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 prepend parameter to the Str::plural() method. Here's what the above looks like, when using that option:

We had {{ Str::plural('attendee', $attendees->count(), prepend: 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.

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
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.

1 participant