Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

shanukk's avatar

Change mysql query to laravel 5.4

I have a mysql query

SELECT * FROM Appraisal_skills WHERE INSTR(`assigned_to`, 6);

Which working well.I want to change this to laravel

I tried

$getskillset=Db::table('Appraisal_skills')->where(`assigned_to`, 6)->instr()->get();

But got an error like BadMethodCallException in Builder.php line 2508: Call to undefined method Illuminate\Database\Query\Builder::instr()

Please correct me.Any help would be appreciated.

0 likes
5 replies
srasch's avatar
srasch
Best Answer
Level 14

INSTR() is currently not supported. You can create the method yourself by extending the QueryBuilder or just use a LIKEstatement which is as fast as INSTR()Which is faster — INSTR or LIKE?.

$getskillset = Db::table('Appraisal_skills')->where('assigned_to', 'like', '%6%')->get();
1 like
Snapey's avatar

That looks really strange. What is the relevance of '6' and why is it found somewhere in the 'assigned_to' field?

1 like
Snapey's avatar

Well it matters if instr is the wrong thing to be using.

If someone came to me and said I can't seem to stab myself with this knife, I would not just show them how to use the knife better.

Please or to participate in this conversation.