douyoupingji7238 2018-10-25 14:01
浏览 152
已采纳

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

  • 写回答

1条回答 默认 最新

  • dounai6613 2018-10-25 14:12
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码