Skip to content

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