使用LIKE的Laravel查询不会返回任何结果 [英] Laravel query using LIKE does not return any result
问题描述
大家好,我目前一直陷在这个问题上.我正在尝试在DB上搜索某些内容,但未返回任何结果.下面是我的代码.
Hi guys I'm currently stuck in this issue. I'm trying to search something on DB and doesn't return any results. Below are my codes.
搜索字符串1 =波士顿凯尔特人队
Search string 1 = Boston Celtics
搜索字符串2 =波士顿凯尔特人队不能
Search string 2 = Boston Celtics Can't
DB post_title =波士顿凯尔特人队不能让公牛的损失影响艰难
DB post_title = Boston Celtics Can’t Let Bulls Loss Impact Difficult Stretch
查询
$data = $searchPost->where('post_title', 'like', '%'.$search.'%')
->orderBy('post_date', 'desc')
->offset($offset)
->limit($limit)
->get();
搜索字符串1返回结果,但搜索字符串2不返回结果.
Search string 1 returns a result but search string 2 is not.
推荐答案
简单,因为您搜索的是不同的字符串.
Simple, because your searching different string.
搜索字符串2"..不能.."使用直引号.
Search String 2 ".. Can't .." use Straight Quotes.
'
DB post_title"..不能.."使用弯引号.
DB post_title ".. Can’t .." use Curly Quotes.
’
供参考:直引号和弯引号
这篇关于使用LIKE的Laravel查询不会返回任何结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!