问题 :
我有一个名为product
带有一些列的表。其中之一是name
。问题是 :
示例条目:
名称:盐粉。
品名:辣椒粉
问题
当我查询时, https://example.com/public/api/products?search=name%3Apowder
我得到 0 个结果。
期待是回归
盐粉和辣椒粉,因为“粉”一词在两者中都很常见。
现在,当我查询 时https://example.com/public/api/products?search=name%3Asalt+powder
,我得到Salt powder
结果。
这是我controller
一直在尝试在索引中实现的内容:
public function index(Request $request)
{
if (Query::has('search')) { ------>>> I know that something is terribly wrong here.
$queryString = Query::get('search');
$products = Products::where('name', 'LIKE', "%$queryString%")->orderBy('name')->paginate(5);
}
try{
$this->productRepository->pushCriteria(new RequestCriteria($request));
$this->productRepository->pushCriteria(new LimitOffsetCriteria($request));
$this->productRepository->pushCriteria(new ProductsOfFieldsCriteria($request));
if($request->get('trending',null) == 'week'){
$this->productRepository->pushCriteria(new TrendingWeekCriteria($request));
}
else{
$this->productRepository->pushCriteria(new NearCriteria($request));
}
$products = $this->productRepository->all();
} catch (RepositoryException $e) {
return $this->sendError($e->getMessage());
}
return $this->sendResponse($products->toArray(), 'Products retrieved successfully');
}
有人可以帮助理解我应该修改什么或哪个语句吗?我尝试过更改,但大多数尝试都以错误告终。任何帮助深表感谢。我可以分享你们可能有兴趣了解的任何文件
qq_遁去的一_1