Laravel find the records between two different numbers in MySQL

Laravel how to find the records between two different number. Like many times we need to find the product price greater than 15 and lower than 525. So how can write a query in Laravel? So it’s too easy to find the record between two number. Let’s see how to create a between condition on laravel eloquent.

<?php
$product = Product::where('status', '=', 1)
    ->whereBetween('price', [15, 525])
    ->get();

Or else you can use the ‘>’ and ‘<‘ condition for the getting same record instead of using ‘whereBetween’. let’s see how we can get the product price between greater than 15 and lower than 525.

<?php
$product = Product::where('status', '=', 1)
    ->where('price','>=',15)
    ->where('price','<=',525)
    ->get();

you can use both of the conditions for getting the product price between 15 to 525.

If you face any issue after using this query please write the comment below.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s