怎么优雅的多字段搜索
$topic = QueryBuilder::for(Topic::class)
->allowedIncludes('category', 'user')
->allowedFilters([
'title',
'auto_title',
'body',
AllowedFilter::exact('category_id'),
AllowedFilter::scope('withOrder')->default('recentReplied'),
])
->paginate(10);
这样的话,就是如下的链接请求
topics?include=user&page=1&filter[category_id]=&filter[title]=关键词&filter[auto_title]=关键词&filter[body]=关键词
这样的搜索就是,要么3个字段都满足才会有结果,要么只能搜索单一字段,怎么优化一下可以3个字段同时搜索呢?
=================
比如像下面这样就可以搜索多字段:
topics?include=user&page=1&filter[category_id]=&filter[keyword]=关键词
本作品采用《CC 协议》,转载必须注明作者和本文链接
推荐文章: