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
Merged

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

merged 2 commits into from
Nov 4, 2019

Conversation

patrickomeara
Copy link
Contributor

@patrickomeara 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
@GrahamCampbell GrahamCampbell changed the title Str::afterLast() and Str::beforeLast() helpers [6.x] Str::afterLast() and Str::beforeLast() helpers Nov 4, 2019
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.

2 participants