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

[5.7] Query builder - dynamic "where" clauses #249

Merged

Conversation

bencorlett
Copy link
Contributor

Being an avid believer of Pull Request or STFU, I agreed with issue #241 and how it was a nice feature of Laravel 3.

I believe that dynamic where clauses, e.g. User::whereFirstNameOrAge('Ben', 21)->first() can sometimes be a nicer way than putting User::where('first_name', '=', 'Ben')->orWhere('age', '=', 21)->first(). For this reason, I've added the functionality back in for dynamic "where" clauses into the query builder.

I also noticed that Sublime has removed a couple of rogue spaces from the end of lines which have been added in. Enjoy.

  • Ben

@JoostK
Copy link
Contributor

JoostK commented Feb 3, 2013

This is buggy when you have a column starting with And or Or, like Orientation. I think the regex has to be something like:

/(And|Or)(?![A-Z])/

Without the i modifier!

@bencorlett
Copy link
Contributor Author

Let me make some tests to isolate this, good spot.

@bencorlett
Copy link
Contributor Author

@JoostK thanks for the spot. Only diff is that the regex you provided will only catch words that start with an And/Or. Needed to use a positive look-ahead for any capital letters after the And/Or match.

@JoostK
Copy link
Contributor

JoostK commented Feb 3, 2013

Oh yes of course, you are right 😃

@bencorlett
Copy link
Contributor Author

@JoostK, like my test method? lol

@JoostK
Copy link
Contributor

JoostK commented Feb 3, 2013

If neither of those fail we are golden! 😉

@Anahkiasen
Copy link
Contributor

+1 for that, liked the dynamic wheres

@drsii
Copy link

drsii commented Feb 13, 2013

+1

3 similar comments
@brunogaspar
Copy link
Contributor

+1

@johnnncodes
Copy link

+1

@dbpolito
Copy link
Contributor

👍

@bencorlett
Copy link
Contributor Author

Just quickly updating the PR for the latest database changes.

Signed-off-by: Ben Corlett <[email protected]>

Conflicts:
	tests/Database/DatabaseQueryBuilderTest.php
taylorotwell added a commit that referenced this pull request Mar 22, 2013
@taylorotwell taylorotwell merged commit 5f98f24 into laravel:master Mar 22, 2013
@bencorlett bencorlett deleted the feature/database-dynamic-where branch March 22, 2013 03:11
@OrkhanAlikhanov
Copy link

Guys, I am so sorry for the inconvenience, I know this is really old PR, but I've just discovered this feature in verison 5.6. But when I tried to find docs for it, I saw that the latest docs that covers this feature is docs for 5.0. In docs for 5.1 and later versions, there is no mention of dynamic where clauses. I've looked at the changelogs etc, I couldn't find a mention of deprecation of this feature. Am I missing something? Is this discouraged to use? Why there is no docs for this feature after 5.0?

@GrahamCampbell GrahamCampbell changed the title Query builder - dynamic "where" clauses [5.7] Query builder - dynamic "where" clauses Mar 24, 2018
@OrkhanAlikhanov
Copy link

It's removed in comit laravel/docs@b99cadb. Maybe it was accidental? Does it worth making PR?

@staudenmeir
Copy link
Contributor

@OrkhanAlikhanov It looks accidental to me. I think you should submit a PR.

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.

10 participants