Laravel Query Using Like Does Not Return Any Result
Solution 1:
Simple, because your searching different string.
Search String 2 ".. Can't .." use Straight Quotes.
'
DB post_title ".. Can’t .." use Curly Quotes.
’
For reference: Straight and curly quotes
Solution 2:
Try the following code:
1) You code might be breaking string because of ' in can't.
$data = $searchPost->where('post_title', 'like', "%{$search}%")
->orderBy('post_date', 'desc')
->offset($offset)
->limit($limit)
->get();
Solution 3:
My first guess would be that an apostrophe might be to blame - in SQL Server the concatenation operator is "+" so you also might want to make sure that is right. Maybe try removing an apostrophe character with:
replace($search, '''', '')
Four single quotes in Microsoft SQL is an escape sequence for a single quote.
Solution 4:
Had the same problem before
try this
$data = $searchPost->where('post_title', 'like', '"%'.$search.'%"')
->orderBy('post_date', 'desc')
->offset($offset)
->limit($limit)
->get();
as you can see there is a " before the % at the start and another after % in the end.
Solution 5:
If you see carefully you Can't in your search and your DB, the ' does not look the same
Can’t vs Can't
When the ' is not the same, sure it can't be searched. Simple.
Post a Comment for "Laravel Query Using Like Does Not Return Any Result"