我正在使用Apiato框架开发API,我正在执行一些搜索操作,我的首页中有一个名为cardDetails的列名,它包含卡片的first4 and last4数字,但是在我的数据库中,它包含两个列,名为first4和last4。
现在我的疑问是,如果用户使用这两个组合的值进行搜索,就意味着它应该从两个列中获取值,您能帮我实现这件事吗?
DetailsRepository.php
public $fieldSearchable=[
'credentials.first4', //credentials is a relationship which is used in Model
'credentials.last4 //first4 and last4 are the columns in details table
]发布于 2022-06-15 06:19:54
下面可以使用Search作为示例,
api.domain.test/v1/endpoint?search=age:17;email:john@gmail.com默认情况下,它是一个或操作,相当于
SELECT * FROM users WHERE age = 17 OR email = 'john@gmail.com';参考文献:http://apiato.io/docs/core-features/query-parameters/#search-join
发布于 2021-12-17 08:06:17
我不太明白你的意思,但这两种方法中有一种是可行的。方法1:
->where('first4', $request->search_word)->orWhere('last4', $request->search_word)方法2:
->when($request->search_word, function ($query) use($request) {
$query->where('first4', $request->search_word);
})
->when($request->search_word, function ($query) use($request) {
$query->where('last4', $request->search_word);
})https://stackoverflow.com/questions/70389952
复制相似问题