Query Comparing a value to the column value using like operator

Hello in Guide 2.0 examples of like operator shows only how to compare the column value to a value type by a user or DBexpress.

For instance if I check that name column contains the word ‘tester’ I’ll write : [’like’, ’name’, ’tester’] will

generate name LIKE ’%tester%’.

But what if I wanna check that the string ‘my name is tester’ contains the value of the column? What I did is [’like’, ‘my name is tester’, ’name’] but I wonder if will not

generate ‘my name is tester’ LIKE ’%name%’.

So how can I tell the generator that the first is a value and the last is the column so check if the string has the value of the column?


I would like to use like operator in a raw sql instruction but I don’t know how to escape special characters(%…). Ex:

custormer::findBySql('Select customers.id where customers.name like %variableContainingValueWithSpecialCharacters%')->all();

Manually I can do it by regex replacing the special characters with escape + special characters before using the variable but is there any simple way(for example by calling a method or function passing the variable)


topics merged

Please do not start another topic with the same subject.


I thought mixing them will make the question ambigous,ok.

Ah, sorry. I didn’t read them carefully.

As to the 2nd question, doesn’t it satisfy you?


So I think you could just write



  ->where('like', 'name', $variableContainingValueWithSpecialCharacters)


The problem is I wanna use it for inner join condition not in where.