Laravel Where Condition with Two Columns Example
Hey Folks,
This detailed guide will cover laravel where with two column example. We will use two column where laravel. I would like to show you laravel whereColumn. I explained simply about table column condition in laravel.
Laravel 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, laravel 8, laravel 9, laravel 10 and laravel 11 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 1:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Item;
class ItemController extends Controller
{
/**
* Write code on Method
*
* @return response()
*/
public function index()
{
$data = Item::select("*")
->whereColumn('created_at','updated_at')
->get();
dd($data);
}
}
Example 2:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Item;
class ItemController extends Controller
{
/**
* Write code on Method
*
* @return response()
*/
public function index()
{
$data = Item::select("*")
->whereColumn('created_at','>','updated_at')
->get();
dd($data);
}
}
I hope it can help you....
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. 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, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- Laravel withCount() with Where Condition Example
- Laravel Where Clause with Function Query Example
- Laravel Sum Query with Where Condition Example
- Laravel Eloquent whereRelation() Condition Example
- Laravel Eloquent whereHas() Condition Example
- Laravel Eloquent Left Join Where Null Condition Example
- Laravel Eloquent whereNotNull() Query Example
- Laravel Eloquent whereNull() Query Example
- How to use whereHas with orWhereHas in Laravel?
- Laravel Relationship Where Condition Example
- Laravel Where Clause with date_format() Example
- How to Use Multiple Database in Laravel?
- Laravel Eloquent Where Like Query Example Tutorial
- Laravel Join with Subquery in Query Builder Example