在Laravel Eloquent中区分大小写



我在我的Laravel Excel Import中有一个construct函数来节省资源。

public function __construct()
{
$this->employees = EmployeeInformation::where('company_id', Auth::user()
->company_id)
->select('id', 'employee_number')->get();
}

我面临的问题是,当我使用$this->employees获得1记录时,它变得区分大小写。例如,Employee NumberEMP1

返回雇员。

$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();

在本例中使用Upper/Lower函数

$this->employees->where('employee_number', 'LIKE', '%'.strtoupper($value).'%')->first();

最新更新