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

Add the the str_before extra helper, it's the inverse of str_after #19940

Merged
merged 1 commit into from Jul 7, 2017

Conversation

Projects
None yet
5 participants
@afsardo
Contributor

afsardo commented Jul 7, 2017

Hello :)

This PR adds an extra string helper, str_before which is exactly the inverse of str_after.


My use case was:

I have an invitation system where I want to create a user with just the email while creating it with a name.
So I would receive the email in the controller, "a.fsardo@gmail.com" and I wanted my user to be:

["name" => "a.fsardo", "email" => "a.fsardo@gmail.com"]

Which would be from str_before(request('email'), '@').


Since Laravel already has a str_after, for me it made sense that this one would be a no-brainer addition.

Hope this is helpful if not at least it was fun, the process of contributing.

@brunogaspar

This comment has been minimized.

Show comment
Hide comment
@brunogaspar

brunogaspar Jul 7, 2017

Contributor

The ModelMakeCommand.php changes are unrelated to this PR and are already part of another PR so you should remove the changes here.

Contributor

brunogaspar commented Jul 7, 2017

The ModelMakeCommand.php changes are unrelated to this PR and are already part of another PR so you should remove the changes here.

@afsardo

This comment has been minimized.

Show comment
Hide comment
@afsardo

afsardo Jul 7, 2017

Contributor

Yes it was my bad, didn't notice it would get added to the PR, was working on something else.

I removed those last 2 commits, which made no sense at all, good catch @brunogaspar

Contributor

afsardo commented Jul 7, 2017

Yes it was my bad, didn't notice it would get added to the PR, was working on something else.

I removed those last 2 commits, which made no sense at all, good catch @brunogaspar

@taylorotwell taylorotwell merged commit f5f6de7 into laravel:master Jul 7, 2017

2 checks passed

continuous-integration/styleci/pr The StyleCI analysis has passed
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@pinguinjkeke

This comment has been minimized.

Show comment
Hide comment
@pinguinjkeke

pinguinjkeke Aug 22, 2017

Contributor

What the difference between this method and standard strtok?
The realisation of this method can be just a redirect to strtok method instead of 10 lines of code.

Contributor

pinguinjkeke commented Aug 22, 2017

What the difference between this method and standard strtok?
The realisation of this method can be just a redirect to strtok method instead of 10 lines of code.

@GlennBags

This comment has been minimized.

Show comment
Hide comment
@GlennBags

GlennBags Aug 24, 2017

Ditto, can do same with strstr() with before_needle = true.

GlennBags commented Aug 24, 2017

Ditto, can do same with strstr() with before_needle = true.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment