Laravel 9 whereColumn Query Example

Websolutionstuff | Oct-21-2022 | Categories : Laravel

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')

 

Example 1:

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();

 

Example 2:

You may also pass a comparison operator to the whereColumn method.

$users = DB::table('users')
                ->whereColumn('updated_at', '>', 'created_at')
                ->get();

 

Example 3:

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:

Recommended Post
Featured Post
How To Add Bootstrap Modal In React JS
How To Add Bootstrap Modal In...

In this article, we will see how to add a bootstrap modal in react js. In this example, we will use the bootstrap m...

Read More

Sep-09-2022

Multi Step Form Wizard jQuery Validation
Multi Step Form Wizard jQuery...

In this article, we will see multi step form wizard jquery validation. Here, we will learn jquery validation for mu...

Read More

Jan-30-2023

Laravel 11 Livewire Form Validation Example
Laravel 11 Livewire Form Valid...

Hello, laravel web developers! In this article, we'll see how to validate forms in laravel 11 Livewire. In lara...

Read More

Jun-12-2024

Laravel 11 CRUD with Image Upload Example
Laravel 11 CRUD with Image Upl...

In this article, we'll see laravel 11 crud with an image upload example. Here, we'll perform a crud operation on...

Read More

Apr-26-2024