2

I am making a search function using Eloquent DB::table, It worked fine but It can't find with both lower case and upper case. Example: When I search ab it has the result. Search Ab, AB can't find anything. What I should change in my code to work with case-sensitive?

I am using PHP 7.X and Laravel 5.7, Postgres SQL

$items = DB::table('element_designs')
    ->join('elements', function($join){
        $join->on('element_designs.id', '=', 'elements.element_design_id')
            ->where('elements.deleted_at', null);
    })
    ->leftJoin('locations', function($join){
        $join->on('elements.location_id', '=', 'locations.id')
            ->where('locations.disable_flg', false);
    })
    ->leftJoin('areas', function($join){
        $join->on('elements.area_id', '=', 'areas.id')
            ->where('areas.disable_flg', false);
    })
    ->where('element_designs.disable_flg', false)
    ->where(function($query) use ($keyword){
        $query->where('element_designs.element_name', 'LIKE', '%'.$keyword.'%')
            ->orWhere('locations.location_name', 'LIKE', '%'.$keyword.'%')
            ->orWhere('areas.area_name', 'LIKE', '%'.$keyword.'%')
            ->orWhere('elements.updated_at', 'LIKE', '%'.$keyword.'%');
    })
    ->select('element_designs.id as element_design_id', 'element_designs.doc_no', 'elements.id as element_id', 'element_designs.element_name', 'locations.location_name', 'areas.area_name',
        'elements.updated_at')
    ->paginate(20);
    });

    return view('element.data', ['items' => $items]);

I want to have the same result when search with ab, Ab or AB. How to do that?

Thanks & Best regards, BienHV

Jaydip kharvad
  • 1,014
  • 6
  • 13
Thien Hoang
  • 143
  • 1
  • 14
  • See this will help you [case-sensitive-sql](https://stackoverflow.com/questions/21213490/laravel-eloquent-ignore-casing) – Muhammad Shareyar Apr 19 '19 at 05:08
  • Hi Jaydip Kharvad, I sawed it before creating this question. It didn't help me resolve this problem. Could you help me in my code post? Thank you so much. – Thien Hoang Apr 22 '19 at 08:15

0 Answers0