📅  最后修改于: 2023-12-03 15:17:13.184000             🧑  作者: Mango
Laravel is a PHP framework that provides various features to develop web applications rapidly. One of the most frequently used features of Laravel is the whereBetween
clause. This clause is used to retrieve records that fall within a specified range of values.
The whereBetween
method is used to filter records between two values:
->whereBetween('column_name', [$value1, $value2])
Suppose we have a books
table with columns title
and price
. We want to retrieve all the books whose price falls between 20
and 50
. We can use the whereBetween
clause as follows:
$books = DB::table('books')
->whereBetween('price', [20, 50])
->get();
This will retrieve all the records that have a price
column value between 20
and 50
.
We can also use multiple whereBetween
clauses in the same query. For example, we want to retrieve records where the price is between 20
and 50
, and the published date is between 2019-01-01
and 2020-12-31
.
$books = DB::table('books')
->whereBetween('price', [20, 50])
->whereBetween('published_date', ['2019-01-01', '2020-12-31'])
->get();
The whereBetween
clause is an essential feature of Laravel that helps to filter records efficiently. We can use it to retrieve records based on specific conditions and ranges. We can also use multiple whereBetween
clauses in the same query to retrieve more specific results.