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

[6.x] Str::afterLast() and Str::beforeLast() helpers #30507

Merged
merged 2 commits into from Nov 4, 2019

Conversation

@patrickomeara
Copy link
Contributor

patrickomeara commented Nov 4, 2019

This PR adds afterLast() and beforeLast() to the Str helper.

These are useful in many situations, recently I have used it to find the type in database notifications, where morph maps cannot be used:

$type = 'App\Notifications\Tasks\TaskUpdated';
Str::afterLast($type, '\\'); // TaskUpdated

and to get the full file name (minus extension) when there are . in the filename. This is useful when processing many file paths from external services (s3) where loading each file is too slow.

$filename = 'photo.2019.11.04.jpg';
Str::beforeLast($filename, '.'); // photo.2019.11.04

Note: PR #28218 added these functions with a case insensitive flag.

@patrickomeara patrickomeara changed the title afterLast and beforeLast helpers added to Str Str::afterLast() and Str::beforeLast() helpers Nov 4, 2019
* includes multibyte support
@patrickomeara patrickomeara force-pushed the patrickomeara:6.x branch from ebe0567 to d2c3d81 Nov 4, 2019
@GrahamCampbell GrahamCampbell changed the title Str::afterLast() and Str::beforeLast() helpers [6.x] Str::afterLast() and Str::beforeLast() helpers Nov 4, 2019
@taylorotwell taylorotwell merged commit 1c44dff into laravel:6.x Nov 4, 2019
1 of 2 checks passed
1 of 2 checks passed
continuous-integration/travis-ci/pr The Travis CI build is in progress
Details
continuous-integration/styleci/pr The analysis has passed
Details
kennith added a commit to kennith/docs that referenced this pull request Nov 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.