0

I am trying to search data in column that has array data type.

[
  {
    "_id": 1,
    "types: [
      ["4","5","6"], ["7","8","9"]
    ]
  },
  {
    "_id": 2,
    "types: [
      ["4","1","2"], ["7","8","9"]
    ]
  },
  {
    "_id": 3,
    "types: [
      ["6","1","2"], ["7","8","9"]
    ]
  },
]

I want to query data that column named types contains value "4". So it will return

[
  {
    "_id": 1,
    "types: [
      ["4","5","6"], ["7","8","9"]
    ]
  },
  {
    "_id": 2,
    "types: [
      ["4","1","2"], ["7","8","9"]
    ]
  },
]

This is what I've tried but it does not work. Employee::where('types', '=', $num)->get();

1 Answers1

0

Cause the value of the type is an array, = can't be a solution. I think you should make a foreach loop with types values and compare them with your required value.

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-ask). – Community Sep 13 '21 at 10:11