Tuesday, May 23, 2017

Laravel Querybuilder join on LIKE

I am attempting to join two tables using the Laravel's query builder however I seem to be having an issue getting the desired result using the query builder, I can however get it quite simply using a raw SQL statement. I simply want to return all mod rows that have the corrosponding value in the tag column in the tags table.

Working SQL query

SELECT * FROM mod JOIN tags ON tags.tag LIKE '%FPS%'

Query Builder

DB::table('mods')
 ->join('tags', function ($join) {
     $join->on('tags.tag', 'like', '%FPS%');
 })
 ->get();

Currently this is telling me: Unknown column '%FPS%' in 'on clause' but I am unsure how else to structure this. I intend on adding more orOn clauses as well as I will want to get results on multiple tags but firstly I just want to get a single tag working.

Appreciate any help.



via XanT

Advertisement