Skip to content

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

2 participants