Php Laravel Elotent区分大小写

Php Laravel Elotent区分大小写,php,mysql,database,laravel,eloquent,Php,Mysql,Database,Laravel,Eloquent,我想检查输入的数据是否已经存在于数据库中。 我一直在尝试输入已经存在的数据(但情况不同)来测试它。 这是我的问题 $existing = AmenityType::all() ->where('type', $req->type) ->first(); 但即使我这么做了,它也不会返回任何东西 ->where('lower(type)', strtolower($req->type)) 数据库排序规则是'utf8mb

我想检查输入的数据是否已经存在于数据库中。 我一直在尝试输入已经存在的数据(但情况不同)来测试它。 这是我的问题

        $existing = AmenityType::all()
        ->where('type', $req->type)
        ->first();
但即使我这么做了,它也不会返回任何东西

->where('lower(type)', strtolower($req->type))
数据库排序规则是
'utf8mb4\u unicode\u ci'

谢谢。

调用
all()
已经返回一个集合,因此where子句将在集合上执行,而不是在db上执行

试着这样做:

$binds = array(strtolower($req->type));

$existing = AmenityType::whereRaw('lower(type) = ?'), $binds)->first();

var_dump($existing);

谢谢,但是上面写着“方法whereRaw不存在”,现在应该是工作了。。问题是在where子句之前调用了
all()
方法!谢谢你指出这一点。现在开始工作了!非常感谢您对这种语言有这么多的经验,但是您可以尝试用
lower('type')
替换
'lower(type)