I’m trying to create a search function for my laravel project.
What I want to achieve is that, for example, I have a companies table, and company name is “ABC-Company”. I want “ABC-Company” to be the search result when people uses the search keywords:
ABC Company, ABCCompany, ABC-Company.
The search can still find if it is the exact match, if it has space instead of the special character, or if it has no space or no special characters (e.g. -
).
Thank you.
I did try several options like using preg_replace on the keyword and on the query builder. removing the spaces and special characters.
Also tried replacing the special characters or spaces with ‘%’, however, the result is incorrect when searching for the keyword without spaces. ABCCompany
will not return the ABC-Company
value
user1787527 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.