-
I am writing to share an idea that I believe would greatly enhance the functionality of Eloquent Builder, specifically concerning search queries utilizing the "whereLike" functionality. Currently, in my projects, I've been utilizing a custom scope named "whereLike" within my models to facilitate search operations based on partial matches across multiple columns. Here's a snippet of the implementation I've been using:
This approach has been effective, but I envision an even more streamlined and expressive solution by integrating a native "whereLike" syntax directly into the Eloquent Builder. The proposed syntax could potentially resemble the following:
By incorporating this feature directly into Eloquent Builder, it would not only simplify the codebase but also enhance readability and maintainability across projects. This native support for "whereLike" queries would undoubtedly streamline the development process for search functionality, making it more intuitive for developers to implement and maintain. I believe this addition would be immensely beneficial to the Laravel community, as it aligns with the framework's ethos of promoting elegant and efficient solutions for common development tasks. I am excited about the potential of this feature and would greatly appreciate your consideration in integrating it into future releases of Laravel. |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 11 replies
-
Hi. Side note: like '%fff% is not recommended because it can't use indexes. If you need that you might be using fulltext search instead (this is also not builtin eloquent). |
Beta Was this translation helpful? Give feedback.
-
As we get Upvotes for this discussion I am closing this discussion and creating an issue for the implementation process |
Beta Was this translation helpful? Give feedback.
-
Building such syntax could helps to resolve the code duplication in our codebase, mainly their should be two search cases
as the same method mentioned above if developers needs to search on relationship we could use as below
@shaedrich Do you suggesting any improvements |
Beta Was this translation helpful? Give feedback.
-
Yes when it is default it should be like |
Beta Was this translation helpful? Give feedback.
Yes when it is default it should be like
User::whereLike('column', $request->query)->get();
User::whereHasLike('column', $request->query)->get();