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

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

Merged
merged 1 commit into from
Jul 7, 2017
Merged

Conversation

afsardo
Copy link

@afsardo 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
Copy link
Contributor

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

@afsardo
Copy link
Author

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
@pinguinjkeke
Copy link
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.

@GlennBags
Copy link

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
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants