0
  • Laravel Version: 9

  • PHP Version: 8.1

  • jenssegers/mongodbn: 3.9

At my model there's a field that represents an array of object, actually are instoke of my record, for example:

{ "item": "journal", "instock": [ { "warehouse": "A", "qty": 5 }, { "warehouse": "C", "qty": 15 } ]},

{ "item": "notebook", "instock": [ { "warehouse": "C", "qty": 5 } ] },

{ "item": "paper", "instock": [ { "warehouse": "A", "qty": 60 }, { "warehouse": "B", "qty": 15 } ] },

{ "item": "planner", "instock": [ { "warehouse": "A", "qty": 40 }, { "warehouse": "B", "qty": 5 } ] },

{ "item": "postcard", "instock": [ { "warehouse": "B", "qty": 15 }, { "warehouse": "C", "qty": 35 } ] }

I would retrieve all record that " warehouse=A and qty > 50 " . It's possible?

Product::query()
    ->where("instock.warehouse",40)
    ->get();
ali amini
  • 11
  • 1
  • Take a look at this: https://laravel.com/docs/9.x/queries#json-where-clauses I think, that you probably should normalize this column into a warehouses table, as well as a pivot table... – Aless55 Nov 29 '22 at 18:17

0 Answers0