In this article, we will see laravel 9 whereBetween query example. The whereBetween() method is used to check value from two columns or a given range of the value. We will learn wherebetween queries in laravel 9. The whereBetween
method verifies that a column's value is between two values.
So, let's see laravel 9 wherebetween query example.
The BETWEEN
operator selects values within a given range. The values can be numbers, text, or dates.
SELECT column_name(s)
FROM table_name
WHERE column_name BETWEEN value1 AND value2;
In this example, we will retrieve all records of employees with salaries between 10000 to 20000.
SELECT * FROM employee
WHERE salary BETWEEN 10000 AND 20000;
In the whereBetween() method first argument is the column name and the second argument is an array of range values.
whereBetween('Column Name', [Range of Value]);
In laravel 9, you can get data from the given range value using the below example query.
$employee = DB::table('employee')
->whereBetween('salary', [10000, 20000])
->get();
In this example, we will retrieve data from a given two date range using the whereBetween().
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Employee;
use Carbon\Carbon;
class RegisterController extends Controller
{
public function index(Request $request)
{
$employee = Employee::whereBetween('joined_at',[$request->join_date,$request->resign_date])->get();
dd($employee);
}
}
You might also like:
In this tutorial, I will show you how to send e-mail using queue in laravel 9, Some time we can see many...
Feb-21-2022
In this tutorial, we will see how to disable future dates in jquery datepicker. In the date picker, today's dat...
Jun-17-2022
In this article, we will see how to import SQL files into MySQL using the command. You can import databases in multiple...
Nov-10-2022
In this article, we will see the laravel 9 livewire datatable example. Here, we will learn how to use livewire data...
Nov-30-2022