In this tutorial, we will see how to use wherecolumn query in laravel. The whereColumn method may be used to verify that two columns are equal.
Given below are examples for wherecolumn query in laravel.
Example 1:
/**
* The attributes that are mass assignable.
*
* @var array
*/
public function index()
{
$users = User::whereColumn('first_name','last_name')
->get();
dd($users);
}
Example 2:
/**
* The attributes that are mass assignable.
*
* @var array
*/
public function index()
{
$users = User::whereColumn('updated_at', '<', 'created_at')
->get();
dd($users);
}
Example 3:
/**
* The attributes that are mass assignable.
*
* @var array
*/
public function index()
{
$users = DB::table('users')
->whereColumn([
['first_name', '=', 'last_name'],
['updated_at', '>', 'created_at'],
])->get();
dd($users);
}
I hope this example helps you.