laravel:如何在 Eloquent Query 中使用 LOWERCASE 函数?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/46238718/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 16:39:19  来源:igfitidea点击:

laravel:how to use LOWERCASE Function in Eloquent Query?

laravel

提问by Jatin Parmar

I want to implement case insensitive search following is my code for search

我想实现不区分大小写的搜索以下是我的搜索代码

/*get the title to search*/
$newsTitle=Input::get('srach_newsTitle')?Input::get('srach_newsTitle'):'';
$query = DB::table('news');
if( strlen($newsTitle) )
    {
        $query->whereRaw('LOWERCASE(`newsTitle`) LIKE ? ',[trim(strtolower($newsTitle)).'%']);
    }

but its says function LOWERCASE is not Defined in My projects following is the error message

但它说函数 LOWERCASE is not Defined in My projects 以下是错误消息

QueryException in Connection.php line 729: SQLSTATE[42000]: Syntax error or access violation: 1305 FUNCTION cpr-laravel.LOWERCASE does not exist (SQL: select count(*) as aggregate from newswhere LOWERCASE(newsTitle) LIKE test%)

Connection.php 第 729 行中的 QueryException:SQLSTATE[42000]:语法错误或访问冲突:1305 FUNCTION cpr-laravel.LOWERCASE 不存在(SQL:选择 count(*) 作为聚合来自newswhere LOWERCASE( newsTitle) LIKE test%)

whats wrong i am doing?plz help

我在做什么错?请帮忙

回答by aaron0207

Use LOWER()

LOWER()

$query->whereRaw('LOWER(`newsTitle`) LIKE ? ',[trim(strtolower($newsTitle)).'%']);