Laravel whereBetween Query Example

Websolutionstuff
1 min readMay 17, 2021

--

In this post we will see laravel whereBetween query example. SQL provides many different type of method or query to get filtered data from database. So, in this post we will learn laravel orWhereBetween query builder example.

Here i will give you code of laravel wherebetween dates example, in below code I have added laravel wherebetween with orwherebetween SQL query as well as Laravel query.

Example of whereBetween() condition in laravel

$students = DB::table('Register')
->whereBetween('RollNo', [1, 50])
->get();

Now I will show you example of whereBetween() query in laravel 6/7/8 and how to write whereBetween() condition in laravel. So first we will see SQL query for better understanding.

SQL OR Example

select * from `Register` where `rollno` between ? and ?

Here we will see another example to get all records between two dates using wherebetween in laravel

<?phpnamespace App\Http\Controllers;use Illuminate\Http\Request;
use App\Register;
use Carbon\Carbon;
class RegisterController extends Controller
{
public function index(Request $request)
{
$names = Register::whereBetween
('created_at',[$request->start_date,$request->$end_date])->get();
dd($names);
}
}

--

--

Websolutionstuff
Websolutionstuff

Written by Websolutionstuff

I am Laravel and PHP Developer. I have also Good Knowledge of JavaScript, jQuery, Bootstrap and REST API. Visit Website: http://websolutionstuff.com/

No responses yet