0

I want to create a filter. But I am facing case-sensitive problem. I have tried with my below code. But It didn't work. I have got error 'call undfiend lcase'.

 $type = strtolower($type);
 $name = strtolower($name);
 $users  = DB::table('daftar.bank_list AS uc')
     ->leftJoin('users.users as u','u.bank_id','=','uc.id')
     ->when($type, function ($query, $type) {
         return $query->where('LCASE'('uc.type'), $type);
     })
     ->when($name, function ($query, $name) {
         return $query->where('LCASE'('uc.name'), $name);
     })
     ->get();

My database is Postgresql.

2 Answers 2

1

Try this:

$type = strtolower($type);
$name = strtolower($name);
$users  = DB::table('daftar.bank_list AS uc')
    ->leftJoin('users.users as u','u.bank_id','=','uc.id')
    ->when($type, function ($query, $type) {
        return $query->where('uc.type','ILIKE', '%'.$type.'%');
    })
    ->when($name, function ($query, $name) {
        return $query->where('uc.name','ILIKE', '%'.$name.'%');
    })
    ->get(); 

You can search by ILIKE query.

Sign up to request clarification or add additional context in comments.

2 Comments

Note that your ILIKE comparison is not the same thing as the equality expression in the OP. You may want to remove the % wildcards.
1

Postgres uses the LOWER() function, not LCASE. Also, if you want to call a native Postgres function, you should be using whereRaw:

$users = DB::table('daftar.bank_list AS uc')
    ->leftJoin('users.users as u', 'u.bank_id', '=', 'uc.id')
    ->when($type, function ($query, $type) {
        return $query->whereRaw('LOWER(uc.type) = ?', [$type]);
    })
    ->when($name, function ($query, $name) {
        return $query->whereRaw('LOWER(uc.name) = ?', [$name]
    })
    ->get();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.