Laravel where dob like $str not working. dob is a date field.
For example dob is 1972-05-28. When I search with $str=1972 it not working.
return $this->builder->where('name','
like', '%'.$str.'%')
->orWhere('nric','like', '%'.$str.'%')
->orWhere('dob','like', '%'.$str.'%');
-------------------------------------------------
Answer :
return $this->builder->whereRaw("cast(dob as char(10)) like '%$str%'")
->orWhere('name','like', '%'.$str.'%')
->orWhere('nric','like', '%'.$str.'%');
For example dob is 1972-05-28. When I search with $str=1972 it not working.
return $this->builder->where('name','
->orWhere('nric','like', '%'.$str.'%')
->orWhere('dob','like', '%'.$str.'%');
-------------------------------------------------
Answer :
return $this->builder->whereRaw("cast(dob as char(10)) like '%$str%'")
->orWhere('name','like', '%'.$str.'%')
->orWhere('nric','like', '%'.$str.'%');
No comments:
Post a Comment