php - 加入 Mongodb 并使用 laravel 在连接表中搜索
问题描述
我想使用 mongodb 数据库连接 laravel 中的表,并在两个表中搜索参数。我用过 has 但它不起作用。我想在具有类似条件的连接表中搜索参数。
我试过有条件。
$CustomerData = Customer::orderBy('_id', 'desc');
$CustomerData = $CustomerData
->where('first_name', 'like', '%' . $search . '%')
->orWhere('middle_name', 'like', '%' . $search . '%')
->with('addressData')
->whereHas('addressData',
function($query) use ($search)
{
$query->orWhere('country', 'like', '%' . $search . '%');
$query->orWhere('state', 'like', '%' . $search . '%');
});
解决方案
@Vishal 检查此示例代码以在不同表之间进行搜索:
代码在这里:
public function SimpleSearch($term)
{
$match = "MATCH(authors.authors) AGAINST(? IN BOOLEAN MODE)";
$match1 = "MATCH(keywords.keywords) AGAINST(? IN BOOLEAN MODE)";
$match2 = "MATCH(research_papers.title) AGAINST(? IN BOOLEAN MODE)";
$match3 = "MATCH(research_papers.abstract) AGAINST(? IN BOOLEAN MODE)";
$researchpapers = DB::table('keywords')
->join('research_papers','keywords.researchpaper_id','=','research_papers.id')
->join('authors','authors.researchpaper_id','=','research_papers.id')
->leftjoin('favorite_models','favorite_models.researchpaper_id','=','research_papers.id')
->whereRaw($match1,array($term))
->orwhereRaw($match2,array($term))
->orwhereRaw($match3,array($term))
->orwhereRaw($match,array($term))
->orderbyRaw($match2."DESC",array($term))
->orderby('dates','desc')
->select('research_papers.id','research_papers.title','research_papers.dates','research_papers.abstract','research_papers.paperlinks','authors.authors','keywords.keywords','research_papers.doi','favorite_models.researchpaper_id','research_papers.websites')
->paginate(10);
return $researchpapers;
}
我希望它会有所帮助。它对我有用。
推荐阅读
- css - CSS中的列中的Flex
- android - 将文件夹标记为在 Android Studio 中生成
- mysql - 逐行查找数字之间的差异mysql
- python - Django - 为没有模型的表创建视图和序列化程序
- visual-studio - 即使框架设置正确,Visual Studio 也无法识别库中的命名空间
- function - Google 表格 - 创建 SKU,将内容自动分成单独的列
- python - 使用 Python 从列表中提取相关元素的问题
- node.js - 如何将 Angular Universal 入口文件重命名为 app.js 并将其移动到应用根目录
- vb.net - 如何在 VB.NET 的 datagridviewcell 中获取光标索引
- javascript - 如何使用firebase将多个文件下载为zip?