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 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥15 (关键词-阻抗匹配,HFSS,RFID标签天线)
  • ¥15 机器人轨迹规划相关问题
  • ¥15 word样式右侧翻页键消失