我想实现不区分大小写的搜索

/*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

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 news where LOWERCASE(newsTitle) LIKE test%)

whats wrong i am doing?plz help

推荐答案

Use LOWER()

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

Laravel相关问答推荐

使用MAATWebSite/EXCEL导入Exel时,不会创建Laravel模型

Laravel:通过数据透视表数据限制多对多Eager 加载

Laravel 验证 - 不同的属性规范

当使用Laravel eloquent查询100000条数据时速度很慢

如何在自引用表上使用 Laravel 的 hasManyThrough

如何在 laravel livewire 中按 bool 值排序数组

判断 Laravel 中是否存在唯一索引键

Guzzle - Laravel如何使用 x-www-form-url-encoded 发出请求

如何在 Laravel 4 中使用没有 id 的 Eloquent 更新数据

Laravel 没有定义

控制器中的 Laravel Auth 用户 ID

如何在没有 Eloquent 的情况下创建 Laravel 模型?

Laravel 随机排序

当表中不存在列时如何将 paginate() 与 having() 子句一起使用

Laravel 5:在同一字符串上使用 bcrypt 给出不同的值

如何在 Laravel 5.1 中改变环境?

从 Artisan 电话中获得响应

调用未定义的方法 Illuminate\Routing\Route::get()

我在哪里放置可以显示 Flash 消息的 Laravel 4 辅助函数?

[Vue 警告]:找不到元素:#app