Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

laravel:how to use LOWERCASE Function in Eloquent Query?

Tags:

laravel

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

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

like image 383
Jatin Parmar Avatar asked Sep 15 '17 11:09

Jatin Parmar


1 Answers

Use LOWER()

$query->whereRaw('LOWER(`newsTitle`) LIKE ? ',[trim(strtolower($newsTitle)).'%']);
like image 82
aaron0207 Avatar answered Sep 19 '22 16:09

aaron0207