Special Characters And Searches With Laravel 3
I am using a grid to display businesses. I'm going to strip down our laravel call to bare minimum so lets say I have about 20,000 businesses and I don't want to load them all if I don't need to. So I am showing a search bar before the grid is loaded to type and query and based on their search input, I load what matches using Laravel into the grid.
The issue I am having is with Special Characters. If in the DB I have a Business Name of Lucky's Bar, and the users search input is Luckys Bar w/o the apostrophe, it doesn't find the result. Same with slashes or dashes.
What is the best approach to accomplishing this?
PHP - Search Statement
public function search($search_input) {
$response = DB::table(self::$table)
->select(array(
'ID',
'Signup_Date',
'Business_Name'
))
->where('Business_Name', 'LIKE', '%'.$search_input.'%')
->order_by('Signup_Date', 'desc')
->get();
return $response;
}
Using Laravel 3, yes I know it is outdated, we have plans to upgrade, but this is a current issue that needs fixing. https://laravel3.veliovgroup.com/docs/database/fluent
Answer
One way, which might be unacceptably slow, is
WHERE REPLACE(field, "'", "") LIKE 'tam osha%"
where in the DB it is stored as Tam O'Shanter
.
Related Questions
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS create a multi select Form field
- → October CMS - Conditionally Load a Different Page
- → How to disable assets combining on development in OctoberCMS
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → OctoberCms component: How to display all ID(items) instead of sorting only one ID?
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?