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.

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

报告相同问题?

悬赏问题

  • ¥15 在获取boss直聘的聊天的时候只能获取到前40条聊天数据
  • ¥20 关于URL获取的参数,无法执行二选一查询
  • ¥15 液位控制,当液位超过高限时常开触点59闭合,直到液位低于低限时,断开
  • ¥15 marlin编译错误,如何解决?
  • ¥15 有偿四位数,节约算法和扫描算法
  • ¥15 VUE项目怎么运行,系统打不开
  • ¥50 pointpillars等目标检测算法怎么融合注意力机制
  • ¥20 Vs code Mac系统 PHP Debug调试环境配置
  • ¥60 大一项目课,微信小程序
  • ¥15 求视频摘要youtube和ovp数据集