Reputation: 9247
$data = Districts::distinct()->whereRaw('LOWER(district) like ?', [strtolower('%'.$district . '%')])->orWhereRaw('LOWER(region) like ?', [strtolower('%'.$district . '%')])->select('region', 'district')->get();
I have this query, but problem is that distinct not working. I get for example three records for same thing. Any suggestion?
Upvotes: 1
Views: 946
Reputation: 53
use this to get one
$data = Districts::select([ DB::raw('DISTINCT(district)'),'region'])->whereRaw('LOWER(district) like ?', [strtolower('%'.$district . '%')])->orWhereRaw('LOWER(region) like ?', [strtolower('%'.$district . '%')])->first();
Upvotes: 0
Reputation: 53
try to this may i think its could be work with region
$data = Districts::select([ DB::raw('DISTINCT(district)'),'region'])->whereRaw('LOWER(district) like ?', [strtolower('%'.$district . '%')])->orWhereRaw('LOWER(region) like ?', [strtolower('%'.$district . '%')])->get();
Upvotes: 0
Reputation: 53
try to this may i think its could be work
$data = Districts::select( DB::raw('DISTINCT(district)'))->whereRaw('LOWER(district) like ?', [strtolower('%'.$district . '%')])->orWhereRaw('LOWER(region) like ?', [strtolower('%'.$district . '%')])->get();
Upvotes: 1