gpt4 book ai didi

php - 在 laravel 5.4 中加入查询

转载 作者:行者123 更新时间:2023-11-30 21:54:45 24 4
gpt4 key购买 nike

我有两个表 1. user 2. shortlist

现在我正在获取用户详细信息,其中我还想要详细信息,例如用户是否被我列入候选名单。我如何使用 join 获取这些数据。常用字段:user.id == Shortlisted 或 user.id = ShortlistedBy

目前我通过这个查询只得到用户数据

$users = DB::table('user')

->select('user.Name','user.Age','user.FatherGotra','user.Profession','user.City','user.State','user.AreYouManglik','user.DOB','user.ProfilePic','user.id')

->where('ShowProfileOnMatrimony','YES')
->where('Mobile','!=',$request->Mobile)
->where('isVerified',1)
->orderBy('user.id','DESC')
->paginate(5);

最佳答案

尝试:

$users = DB::table('user')->select('user.Name','user.Age','user.FatherGotra','user.Profession','user.City','user.State','user.AreYouManglik','user.DOB','user.ProfilePic','user.id','shortlist.isShortlisted as isshortlist')
->leftJoin('shortlist', 'user.id', 'Shortlisted')
->leftJoin('shortlist as ShortlistedBy', 'user.id', 'shortlist.ShortlistedBy')
->where('ShowProfileOnMatrimony','YES')
->where('Mobile','!=',$request->Mobile)
->where('isVerified',1)
->orderBy('user.id','DESC')
->paginate(5);

更多信息在这里:https://laravel.com/docs/5.4/queries#joins

关于php - 在 laravel 5.4 中加入查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45691325/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com