In Laravel, you can easily filter the value between two numbers by using the whereBetween method, one of the numbers should be inclusive and the other is exclusive. If you want a query where a value is greater than or equal to X and less than Z. 

You can use the where method in two ways by following the below instructions.

$results = DB::table('your_table')
    ->where('your_column', '>=', $X)  // Greater than or equal to X
    ->where('your_column', '<', $Z)   // Less than Z
    ->get();

In this code:

  • Replace ‘your_table’ with the actual database table name that you create.
  • Replace ‘your_column’ with the column you’re querying.
  • $X is the lower value(inclusive).
  • $Z is the upper value(exclusive).

If you are using Eloquent model, your code should be like this:

$results = YourModel::where('your_column', '>=', $X)
    ->where('your_column', '<', $Z)
    ->get();

This will return all records from your_column that are greater than or equal to $X and less than $Z.

Share.
Leave A Reply

Exit mobile version