This article will examine the whereBetween() function available in Laravel Eloquent. This method checks to see whether the value of a column falls inside a specified range. In this article, we will go through some basic examples of whereBetween(), which we will use to filter the entries in our database.
The example below will demonstrate how to execute whereBetween queries using the eloquent method that Laravel provides.
In the first example, we will filter our entries between two specified dates using the whereBetween() function.
In the example shown below, there is a UserController. Here, we'll find out who has signed up in the last week.
In the preceding example, we filtered down our entries by passing the two dates $from and $to to the whereBetween() function of the Laravel framework.
We'll use the number value in the second example to filter database entries. For this example, we have a UserController that will have a filterUser() method. This method will return the user based on a minimum and maximum age.
In the second example, we developed a method that received two parameters, $minimum and $maximum, which would filter out users whose ages fall between the specified age range.
When you are dealing with a vast dataset and need to filter it according to your specifications, the whereBetween function of Laravel is a great help.