samedi 26 septembre 2015

Proper Model/Database structure in Laravel 5

I've been working on a ecommerce project to learn Laravel 5. I know how I would set up the database and use joins to get the data how I need it, but I'm still a little rough on the MVC aspect of things, so I'm not sure the proper way to use pivot tables to integrate with Laravel 5's MVC (especially if there isn't something like a manyThroughMany method).

This is a rough sketch of my proposed database: ![enter image description here

There are 3 main Models here, the products, categories, and items. The Products will be broad groups of items (think shirts, pants, etc.) Where as categories would be things like brands, sizes, colors, etc.

A Product will have many categories (this will determine what filters show up on view), and a category will have many values (the options that will show up in a filter, such as Color: Red, Green, Blue).

An Item will belong to a Product, and will have multiple category values. An example item would be something like:

  • Belongs to the "Shirt" Product
  • Has a Category_Value of "Medium" (which belongs to the "Size" Category)
  • Has a Category_Value of "Red" (which belongs to the "Color" Category).

This may be the entirely wrong database structure for a Laravel app, in which case, please let me know what the proper structure is.

In addition, if this the right, or at least an acceptable structure, how does this translate into Models? I obviously have a Product Model, a Category Model, and an Items Model, all with various hasMany type methods, but I'm not sure of how to translate an Item's Category_Value into a category without an expensive cross over between Models.



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1O13sFz
via IFTTT

Aucun commentaire:

Enregistrer un commentaire