其中,带变量的RAW Laravel

其中,带变量的RAW Laravel,laravel,postgresql,query-builder,Laravel,Postgresql,Query Builder,我正在尝试执行此查询,但出现错误(格式错误的UTF-8字符,可能编码不正确): 我正在尝试将UPPERsql函数添加到查询中。对于直接sql,查询应为: select * from my_table where UPPER(name) = 'HELLO' 其中$upper\u name=你好。呸。。。我明白了: DB::table('my_table')->select(DB::raw("id")) ->whereRaw('UPPER(name) = ?', $upper_

我正在尝试执行此查询,但出现错误(格式错误的UTF-8字符,可能编码不正确):

我正在尝试将
UPPER
sql函数添加到查询中。对于直接sql,查询应为:

select * from my_table
where UPPER(name) = 'HELLO'
其中
$upper\u name
=你好。

呸。。。我明白了:

DB::table('my_table')->select(DB::raw("id"))
    ->whereRaw('UPPER(name) = ?', $upper_name)
    ->pluck('id')->first();
这是最简单的方法。希望对你有帮助
-将文本转换为大写

是的,
whereRaw
您可以在字符串上完成整个语句,也可以像
->whereRaw('upper(name)=?',$upper_name)
->whereRaw(“upper(name)=$upper_name”)
谢谢,好多了。我使用的是PostgreSQL,但是使用DB:raw更好。
DB::table('my_table')->select(DB::raw("id"))
    ->whereRaw('UPPER(name) = ?', $upper_name)
    ->pluck('id')->first();
DB::table('my_table')->select('id')
    ->where(DB::raw("UCASE(name)"), $upper_name) 
    ->first();