Skip to content

[10.x] feat add whereLike() and whereLikeContain()#46405

Closed
Haythamasalama wants to merge 4 commits into
laravel:10.xfrom
Haythamasalama:feat-where-like
Closed

[10.x] feat add whereLike() and whereLikeContain()#46405
Haythamasalama wants to merge 4 commits into
laravel:10.xfrom
Haythamasalama:feat-where-like

Conversation

@Haythamasalama
Copy link
Copy Markdown

@Haythamasalama Haythamasalama commented Mar 9, 2023

add methods that handle queries for performing 'where like' searches in the database.

  • whereLike(), whereNotLike() , orWhereLike()
  • whereLikeContain() , whereNotLikeContain() , orWhereLikeContain()
 // select * from `users` where `name` like laravel;
  
 User::whereLike('name', 'laravel')->get();
  
// select * from `users` where `name` like "%laravel%";

 User::whereLikeContain('name', 'laravel')->get();
 // select * from `users` where `name` like laravel or `name` like forge;
 User::whereLike('name', 'laravel')->orWhereLike('name','forge')->get();
 
 // select * from `users` where `name` like "%laravel%" or `name` like "%forge%";
 User::whereLikeContain('name', 'laravel')->orWhereLikeContain('name','forge')->get();
 
 // select * from `users` where `name` not like laravel and `name` not like "%forge%";
 User::whereNotLike('name', 'laravel')->whereNotLikeContain('name','forge')->get();

* add `whereLike()`
* add `whereLikeContain()`
* add `orWhereLike()`
* add `orWhereLikeContain()`
* add `whereNotLike()`
* add `whereNotLikeContain()`
@ankurk91
Copy link
Copy Markdown
Contributor

ankurk91 commented Mar 9, 2023

This has been attempted many times.
We should stop adding more alias methods to Builder.

Btw it does not cover all use cases.

How to produce this query

select * from stores where name like "apple%"

select * from stores where name like "a%e"

There are many others cases

@driesvints
Copy link
Copy Markdown
Member

Thank you. Please try to search PR's before submitting.

@driesvints driesvints closed this Mar 9, 2023
@Haythamasalama
Copy link
Copy Markdown
Author

This has been attempted many times. We should stop adding more alias methods to Builder.

Btw it does not cover all use cases.

How to produce this query

select * from stores where name like "apple%"

select * from stores where name like "a%e"

There are many others cases

You Can Use like this or other cover all use cases

Stores::whereLike('name',"apple%")->get();
Stores::whereLike('name',"a%e")->get();

@Haythamasalama
Copy link
Copy Markdown
Author

Thank you. Please try to search PR's before submitting. @driesvints

🧐 Hmm, I think it's useful, just like other query builders such as whereBetween() ...etc. and whereLike() it supports many other cases in the where clause.

@newtonjob
Copy link
Copy Markdown

I'm surprised this is closed without any practical reason.

LIKE is a very common SQL operator and probably the only one that doesn't have a helper method yet.
Sometimes I find myself reaching for it by default, only to realise such a method doesn't exist.

We have helper methods for several operators like IN, NULL, BETWEEN, DATE, FULLTEXT, etc.

Why is LIKE excluded? Are there any downsides?

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.

4 participants