[Vuejs]-Laravel: Find exact match, case sensitive

4👍

You have to use BINARY

use DB;
...
public function search(){
    if ($search = \Request::get('q')) {
        $patrons = Patron::where(function($query) use ($search){
            $query->whereRaw("BINARY `barcode` = '$search'");
            // or
            // $query->where(DB::raw("BINARY `barcode`), $search);
        })->paginate(20);
    }else{
        $patrons = Patron::latest()->paginate(5);
    }

    return $patrons;
}

Also if you are using one where and not chaining it to other conditions you don’t need to use function inside where. you can simply write:

use DB;
...
public function search(){
    if ($search = \Request::get('q')) {
        $patrons = Patron::where(DB::raw("BINARY `barcode`"), $search)->paginate(20);
    }else{
        $patrons = Patron::latest()->paginate(5);
    }

    return $patrons;
}

Leave a comment