我在我的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 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();
在本例中使用Upper/Lower函数
$this->employees->where('employee_number', 'LIKE', '%'.strtoupper($value).'%')->first();