0

I'm using query builder with laravel and i'm trying to get the equivalent of

SELECT name
     , firstname 
FROM emp
WHERE name+' '+firstname LIKE '%test%'

in query builder? How could I have the same result?

1

3 Answers 3

1

you can do that in whereRaw() like this

DB::table('emp')->whereRaw("name+' '+firstname LIKE '%test%'")->select('name', 'firstname')->get();

hope it's work for you!

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much ! This is what i'm looking for
1
 $result = DB::table('emp')->select('name', 'firstname')->where(DB::raw("CONCAT('name', ' ', 'firstname')"), 'LIKE', '%'. 'test' .'%')->get();

Comments

0

Try using CONCAT for multiple column

DB::table('emp')->Where(DB::raw("CONCAT(`name`, ' ', `firstname`)"), 'LIKE', "%test%")->select('name', 'firstname')->get();

hope this will help.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.