Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

peeknot's avatar

Query relationship table with column that its data is an parsed array(1,2,3,4,5,6)

I have a string column in the table that have this kind of data // 1,2,3,4,5,6 comma separated data, supposedly this id has equivalent value to the another table.

I have the solution that I can get the data of the mentioned ids but its a bit mess. This is the step that I have solution

  1. Get all data first
  2. Loop all the data
  3. Convert the column that has comma separated data to array
  4. Loop the converted column
  5. Query to another table
  6. And save the query data

Is there an easy way to achieve this via eloquent query?

Thanks

0 likes
1 reply
vincent15000's avatar
Level 63

Why are you storing JSON data for related tables ? Wouldn't it be easier to have a pivot table ?

With JSON data, you will loose performance.

1 like

Please or to participate in this conversation.