Laravel whereBetween & whereNotBetween Eloquent Query with Tutorial


Share:
Published By: Admin, Published On: Apr 30, 2021, Category: Laravel

Hello Friends,

Now let's see example of how to use whereBetween() and whereNotBetween() in laravel. This is a short guide on laravel if whereBetween(), whereNotBetween(). We will use how to use whereBetween() and whereNotBetween() in laravel. Here you will learn how to use whereBetween() and whereNotBetween() in laravel. Let's get started with how to whereBetween() and whereNotBetween() use in laravel.

Here i will give you many example and understand how works this whereBetween and whereNotBetween functions one by one in laravel.

Example whereBetween():

The whereBetween method verifies that a column's value is between two values.

/**
    * Write code on Method
    *
    * @return response()
*/
public function index()
{
    $foods = Food::whereBetween('stock', [1, 10])
                    ->get()
                    ->toArray();
    dd($foods);
}
Output:
array:2 [▼
  0 => array:5 [▼
    "id" => 1
    "name" => "burger"
    "stock" => 10
    "created_at" => "2020-12-23T04:59:46.000000Z"
    "updated_at" => "2020-12-23T04:59:46.000000Z"
  ]
  1 => array:5 [▼
    "id" => 2
    "name" => "burger"
    "stock" => 9
    "created_at" => "2020-12-23T07:13:06.000000Z"
    "updated_at" => "2021-01-02T06:44:33.000000Z"
  ]
]
Example whereNotBetween():

The whereNotBetween method verifies that a column's value lies outside of two values.

/**
    * Write code on Method
    *
    * @return response()
*/
public function index()
{
    $foods = Food::whereNotBetween('stock', [1, 10])
                    ->get()
                    ->toArray();
    dd($foods);
}
Output:
array:1 [▼
  0 => array:5 [▼
    "id" => 3
    "name" => "pizza"
    "stock" => 20
    "created_at" => "2020-12-24T05:07:51.000000Z"
    "updated_at" => "2020-12-24T05:07:51.000000Z"
  ]
]

It will help you....

Share: