Support the ongoing development of Laravel.io →
Views Database Eloquent

I have four tables.

  • option_groups
  • options
  • product_options
  • product_images

Tables Structure

option_groups

id name

options

id name option_group_id

product_options

id product_id option_id option_group_id

product_images

id product_id images isfeatured

so what basically i want to store options according to option_group_id.

ex:

i'm creating a product T-Shirt in product_options table the records must like this.

id => 1 product_id => 1 option_id => // 1 for red and so on; 7 for small and so on; option_group_id => // 1 for color; 2 for size;

i'm fully confused how to it and how to store multiple options for single product.

every product have multiple options and images like

colors => ['red','green', 'blue']

size => ['small','Medium','Large']

images => ['img1.png','img2.png','img3.png','img4.png','img5.png']

// total 5 images limit

isfeatured => true //for img1.png

please help me how to do this...

Last updated 3 years ago.
0

Hi Rashid,

I cannot see how those tables are supposed to achieve the set goal. Firstly you should name things properly. You should have attributes, each having several possible attribute values. It is unclear whether you want a product to have many attributes and then in the order (or something) to have attribute values specified for them; or a product to have a direct relation with attribute values. Rethink your database schema. This looks like you are moving towards an EAV database, which is quite difficult to work with.

Fitzberg

0

Sign in to participate in this thread!

PHPverse

Your banner here too?

Rashid Ali realrashid Joined 27 Nov 2017

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.