php - 在 Laravel Eloquent 中区分大小写的第二个地方
问题描述
我的 Laravel Excel 导入中有一个构造函数来节省资源。
public function __construct()
{
$this->employees = EmployeeInformation::where('company_id', Auth::user()
->company_id)
->select('id', 'employee_number')->get();
}
我面临的问题是当我$this->employees
用来获取 1 记录时它变得区分大小写。例如Employee Number
是EMP1
这将返回员工。
$this->employees->where('employee_number', 'EMP1')->first();
这将返回 null。
$this->employees->where('employee_number', 'emp1')->first();
有什么办法可以节省资源吗?我想要实现的是使用$this->employees
来搜索员工的记录,以避免在我的导入中查询每行。
解决方案
您可以使用 LIKE %...%
$this->employees->where('employee_number', 'LIKE', '%emp1%')->first();
推荐阅读
- bash - 将 curl 响应中的 JSON 值传递给新文件
- css - 如果我们在 CSS 网格中有更多列,为什么内容大小会不同?
- php - CakePHP 3.6:连接查询
- arrays - 反应本机排序问题
- python-3.x - 在python中按索引组迭代
- javascript - 从法国文化中的 kendo-ui 解析日期
- javascript - 将附件和一些附加参数上传到 MVC 控制器
- javascript - 在移动 Web 浏览器中使用 Facebook JavaScript SDK 的 FB.login 会打开新选项卡而不是原生 Facebook 应用程序
- mysql - 求和时间值 MySQL
- android - EndlessRecyclerViewScrollListener 不显示 recyclerview 上的所有项目