Home Laravel How to use Where Condition with Two Columns in Laravel ?

How to use Where Condition with Two Columns in Laravel ?

by Shahriar Sagor

Today now in this post i will show you How to use Where Condition with Two Columns in Laravel ? We know in Laravel introduce whereColumn() in the Query Builder, on that way we can compare between two column as like simple where condition. So sometimes We may need to check this type of condition.

So we can use wherecolumn() eloquent function in any version of laravel 6, laravel 7 and laravel 8 application.

Now in this example , i have a simple table as name “items” and i want to get the only created_at and updated_at column should be equals. So we can also check the bellow laravel eloquent as like as bellow:

Example 1:
$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);

Read Also: How we can create virtual host in ubuntu apache?

Thanks for read. I hope it help you. For more you can follow us on facebook

close

You may also like