Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.x] Add a wordCount() string helper #36990

Merged
merged 3 commits into from Apr 14, 2021
Merged

[8.x] Add a wordCount() string helper #36990

merged 3 commits into from Apr 14, 2021

Conversation

jeroenvanrensen
Copy link
Contributor

@jeroenvanrensen jeroenvanrensen commented Apr 14, 2021

Hi everyone,

This is my first contribution to the Laravel framework.

I added a wordCount() string helper.

Now you can shorten this:

public function getWordCountAttribute(): int
{
    $text = Str::of($this->body)
        ->replace('x', 'y') // do something
        ->replace('a', 'b'); // do something else

    return str_word_count($text);
}

To:

public function getWordCountAttribute(): int
{
    return Str::of($this->body)
        ->replace('x', 'y') // do something
        ->replace('a', 'b') // do something else
        ->wordCount();
}

At least to me, this seems a lot nicer.

If this get's merged, I would like to write the corresponding docs.

Thank you!
Jeroen

@GrahamCampbell GrahamCampbell changed the title Add a wordCount() string helper [8.x] Add a wordCount() string helper Apr 14, 2021
@taylorotwell taylorotwell merged commit 591bb23 into laravel:8.x Apr 14, 2021
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.

None yet

2 participants