Laravel Eloquent Compare two Columns Values

 Laravel Eloquent Compare two Columns Values in 2 way


=> 1st way

->whereRaw('table_1.name = table_2.name');


=> 2st way

->whereColumn('table_1.name', 'table_2.name');


=> Example

$users = DB::table('users')
->whereColumn('first_name', 'last_name')
->get();


=> Example with multiple columns


$users = DB::table('users')
->whereColumn([
['first_name', '=', 'last_name'],
['updated_at', '>', 'created_at'],
])->get();



Note

You can used operation used like 
'=,<,>,<=,>= etc




1 comment:

Other post

1) The create() Method The  create()  method is a powerful and convenient way to store data in your Laravel application. It is typically use...