首页 > 解决方案 > 在laravel中雄辩的where子句中连接两列

问题描述

在我的数据库中,country_codephone_number是两个不同的字段。用户正在输入一个包含国家代码和电话号码的字符串来登录。为了验证这一点,我必须在雄辩的 where 子句中country_code连接列。phone_number

有人可以告诉我该怎么做吗?我在下面给出我的查询。

$user  = self::where('phone_number', '=', $username)->get()->first();

标签: phpmysqllaraveleloquentlumen

解决方案


您可以将 whereRaw 与原始 SQL 表达式一起使用,并将参数与第二个参数绑定。

whereRaw("CONCAT(`country_code`, `phone_number`) = ?", [$username]);

推荐阅读