Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel Eloquent Compare Column Values

Eloquent's where() seems not working when comparing two column values. How to fix it?

Sample code:

->where('table_1.name', '=', 'table_2.name') 

But works on:

->where('table_1.name', '=', 'john') 
like image 983
Jake Opena Avatar asked May 19 '15 16:05

Jake Opena


2 Answers

Escaping is unnecessary in this case, you can use whereRaw():

->whereRaw('table_1.name = table_2.name') 
like image 196
Limon Monte Avatar answered Oct 03 '22 22:10

Limon Monte


You can use where column:

->whereColumn('table_1.name', 'table_2.name') 
like image 21
Carolyn Lim Avatar answered Oct 04 '22 00:10

Carolyn Lim