php - 在laravel中雄辩的where子句中连接两列
问题描述
在我的数据库中,country_code
和phone_number
是两个不同的字段。用户正在输入一个包含国家代码和电话号码的字符串来登录。为了验证这一点,我必须在雄辩的 where 子句中country_code
连接列。phone_number
有人可以告诉我该怎么做吗?我在下面给出我的查询。
$user = self::where('phone_number', '=', $username)->get()->first();
解决方案
您可以将 whereRaw 与原始 SQL 表达式一起使用,并将参数与第二个参数绑定。
whereRaw("CONCAT(`country_code`, `phone_number`) = ?", [$username]);
推荐阅读
- python - 访问两个协程之间的公共共享变量
- reactjs - 材质 UI Snackbar autoHideDuration 为 null
- html - 当步长大于剩余值时,HTML Range 输入不会一直填充
- sprockets - 在请求期间创建新样式表然后立即要求它会产生错误
- ruby-on-rails - 定义了 2 个模型之间的一对一关系,但似乎仍然能够建立一对多
- python - 命令提示符无法识别 PATH 中的更改。我该如何解决?
- python - 在 python 中清理这个 int64 变量
- matlab - 如何以编程方式导出两个模型的 visdiff 结果(Matlab 版本 <= R2016b)?
- ios - 谷歌搜索应用程序是否阻止通用链接
- python - 使excel数据csv兼容