Laravel搜索特定单词

时间:2016-02-10 03:50:02

标签: php laravel

我想搜索特定的单词而不是表格中的字母。现在我使用like,但它不像预期的那样:

//  Category Table
-----------------------------------------------------
| id       |   amount           |  updated_at       |
+----------+--------------------+-------------------+
| 1        | Bread              |2016-02-10 13:17:29|  
| 2        | Bread Loaf         |2016-02-10 13:17:29|
| 3        | Bread1             |2016-02-10 13:17:29|
+----------+--------------------+-------------------+

例如,我搜索单词"面包":

$words = "bread";
$query = Category::where(function ($query) use ($words) {
              $query->where('name', 'like', '%' . $words . '%');
         })->get();

结果:所有的面包都出来了。

我的期望是" Bread1"没有得到查询。只有面包和面包。

我应该在查询中添加什么内容?

1 个答案:

答案 0 :(得分:0)

您可能想尝试此SELECT * FROM产品WHERE product_name RLIKE“[[:<:]] bread [[:>:]]”; Same Question Here

相关问题