PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, January 13, 2022

[FIXED] Concat first name and last name in where clause in laravel mongodb to search

 January 13, 2022     ajax, eloquent, laravel, mongodb, php     No comments   

Issue

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


Solution

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);
});


Answered By - kapitan
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing