0

"I want to create a filter where the data is taken from nested JSON."

Previously, I had a table named history_product with the column transaction_details. I want to create a filter based on unit_details. However, I encountered difficulties when using whereJsonContains. I tried using where based on transaction_id with a query like this:

$q->whereJsonContains('history_product.transaction_details', ['transaction_id' => 9]);

With this query, I successfully obtained the expected data. However, when I made a query like this:

$q->whereJsonContains('history_product.transaction_details', ['place->id' => 3]);

OR

$q->whereJsonContains('history_product.transaction_details', ['place' => ['id' => 3]]);

The system did not return the desired data. Is there any deficiency or mistake in the query I made?

I greatly appreciate assistance from everyone. Thank you.

Here is the data structure of the transaction_details field :

[
  {
    "transaction_id": 9,
    "course_id": 6,
    "course_name": "x product",
    "qty": "100.000",
    "qty_request": "100.000",
    "weight": 7500,
    "transaction_type": 1,
    "place": "{\"id\":3,\"company_id\":1,\"type\":2,\"type_place\":1}",
    "id": 9
  }
]
2
  • 1
    place contains a string, not JSON. Commented Dec 17, 2023 at 12:12
  • did you try removing backslashed from place value? Commented Dec 18, 2023 at 7:53

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.