0

I want to get data that Price is greater than or equal to a specified value (taken from the input).

$minPrice = $request->min_price;
$maxPrice = $request->max_price;

$value = Dproduct::where(['status' => 1])->where('price', '>', $minPrice)->get();

But the Price is JSON in database, I can't get it. Currencies such as: VND, USD, TWD,...

enter image description here

All answers are respected! Thanks so much!

Hoang Dinh
  • 157
  • 1
  • 10
  • Is the database column of the type json? and which laravel version are you using? You can use [json where clauses](https://laravel.com/docs/master/queries#json-where-clauses) – Remul Nov 11 '19 at 15:25
  • 1
    @Remul I save price is json, my version is 5.7 – Hoang Dinh Nov 11 '19 at 15:27

1 Answers1

0

if you are using laravel 5.7 or greater then you may be able to select within the JSON. See the docs here for more details.

Note: for this to work you must use json data type for your field in database.

$minPrice = $request->min_price;
$maxPrice = $request->max_price;

$value = Dproduct::where(['status' => 1])->where('price->USD', $minPrice)->get();
Muhammad
  • 6,725
  • 5
  • 47
  • 54