Laravel搜索特定单词 [英] Laravel search for specific word
本文介绍了Laravel搜索特定单词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想搜索特定单词而不是表格中的字母.现在我正在使用like
,但它不像预期的那样:
I want to search for specific word instead of letter from a table. Right now i'm using like
but it not like expected:
// 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|
+----------+--------------------+-------------------+
例如,我搜索单词面包":
For example I search for word "bread":
$words = "bread";
$query = Category::where(function ($query) use ($words) {
$query->where('name', 'like', '%' . $words . '%');
})->get();
结果:所有面包都出来了.
The result: all bread is coming out.
我期望的是"Bread1"没有得到查询.只有面包和面包.
What I expected is "Bread1" is not get query. Only Bread and Bread Loaf.
我应该在查询中添加什么?
What should I add to my query?
推荐答案
您可能想尝试一下SELECT * FROM products where where product_name RLIKE"[[:< ;:]]面包[[:>:]]"; 此处有相同问题
You may want to try this SELECT * FROM products WHERE product_name RLIKE "[[:<:]]bread[[:>:]]"; Same Question Here
这篇关于Laravel搜索特定单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文