Home > Back-end >  Concat first name and last name in where clause in laravel mongodb to search
Concat first name and last name in where clause in laravel mongodb to search

Time:12-25

I am trying concat first name and last name in Laravel but it's not working. i am using mongo db

i was tried this sql query but its not working

->orWhere(\DB::raw("CONCAT(`last_name`, ' ', `first_name`)"), 'LIKE', "%".$search."%"); 

can anyone find the alternate solution of concat in mongodb

Thank you in advance

CodePudding user response:

Can't you do something like:

$full_name = explode(" ", $search);
$last_name  = $full_name[0];
$first_name = $full_name[1];

Then:

->orWhere(function($query){
  $query->where('last_name', $last_name)->where('first_name', $first_name);
});
  • Related