Laravel - Where Condition with Two Columns Example

By Hardik Savani | July 29, 2016 | Category : Laravel


Laravel 5 introduce whereColumn() in Query Builder, that way we can compare two column like simple where condition. We sometimes require to check this type of condition.

you can use wherecolumn() eloquent function in laravel 6, laravel 7 and laravel 8 application.

In this example code, i have simple "items" table and i want to get only created_at and updated_at column should equals. So you can also check bellow laravel eloquent as bellow:

Example:

$data = DB::table("items")

->whereColumn('created_at','updated_at')

->get();

print_r($data);

Example 2:

$data = DB::table("items")

->whereColumn('created_at','>','updated_at')

->get();

print_r($data);

I hope it can help you....




Hardik Savani
My name is Hardik Savani. I'm a full-stack developer, entrepreneur and owner of Aatman Infotech. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.
Follow Me: Github Twitter
***Do you want me hire for your Project Work? Then Contact US.

We are Recommending you: