In this article, we will see laravel 9 whereColumn() query example. The whereCoulmn method is used to verify whether two columns are equal or not. So, we will learn whereColumn in laravel 9.
Laravel also provides orWhereColumn() method. So, you can also use whereColumn() with orWhereColumn() method in laravel.
So, let's see laravel 9 whereColumn() and compare two columns in laravel 9.
Syntax of whereColumn()
whereColumn('column name', 'operator', 'compare column name')
In this example, we will retrieve all those employee's records which are both column equals.
$employee = DB::table('employee')
->whereColumn('first_name', 'last_name')
->get();
You may also pass a comparison operator to the whereColumn
method.
$users = DB::table('users')
->whereColumn('updated_at', '>', 'created_at')
->get();
You may also pass an array of column comparisons to the whereColumn
method. These conditions will be joined using the and
operator.
$users = DB::table('users')
->whereColumn([
['first_name', '=', 'last_name'],
['updated_at', '>', 'created_at'],
])->get();
You might also like:
In this example we will see example of laravel 8 class numberformatter not found. For numberformatter we need PHP 5...
Dec-27-2021
In this article, we will see laravel 9 custom helper function example. As we all know laravel provides many re...
Mar-07-2022
Today in this post we will see multi step form example in laravel, here we will create laravel multi step form example.&...
Jul-21-2021
In this article, we will see a dependent dropdown in laravel 9 vue js. Here, we will learn how to create a dependent dro...
Dec-15-2022