Magento 2 keeps a product's attributes in 6 tables. In Laravel, the same product can be 1 row with a JSON column. Each design makes one thing free and charges for another. Magento gives you new attributes without a migration and charges for them in joins. Laravel gives you one indexed read and charges for it in migrations.
Magento: entity, attribute, value
catalog_product_entity holds the product itself: SKU, type, attribute set, little else. The attribute values sit in 5 more tables, one per data type: _int, _varchar, _decimal, _text and _datetime. Every value row has the same 5 columns: value_id, attribute_id, store_id, entity_id, value. That store_id is why a product name can differ per store view (usually one per language) without any extra schema. The layout is called EAV: entity, attribute, value.
Images, tier prices and category links have tables of their own. These 6 hold only the attributes.
The upside: attributes without migrations
Adding an attribute doesn't touch the table structure. Whether it comes from the admin or from a data patch like the one below, it's a row in eav_attribute. A fresh Magento 2.4.9 install from the GitHub repository already has 61 of them for products.
class AddPaperWeight implements DataPatchInterface { public function __construct( private ModuleDataSetupInterface $setup, private EavSetupFactory $eavSetupFactory ) {} public function apply(): self { // no ALTER TABLE: a row in eav_attribute, values in catalog_product_entity_int $this->eavSetupFactory->create(['setup' => $this->setup]) ->addAttribute(ProductAttributeInterface::ENTITY_TYPE_CODE, 'paper_gsm', [ 'type' => 'int', 'label' => 'Paper weight, g/m2', 'required' => false, ]); return $this; } // + getDependencies() and getAliases(), both return [] } On that install the patch created attribute 137, paper_gsm, with backend type int. catalog_product_entity got no new column. Saving a product with 130 g/m² wrote one row into catalog_product_entity_int: attribute 137, store 0, value 130.
The cost: joins on every filter
Filters pay for that flexibility. Filtering a product collection by paper_gsm produces an INNER JOIN to catalog_product_entity_int, scoped to the attribute and the store. Add a sort by name and the same query has 3 JOINs: a name can differ per store view, so it joins the default value and the store's value. Every attribute stored in the value tables adds joins of its own when you filter or sort by it.
So category pages, search and layered navigation (the filter sidebar) don't filter on EAV. An indexer copies the values of searchable, filterable and sortable attributes into the search engine, and those pages take their product IDs from it. Prices come from an index table, catalog_product_index_price. Only then are the EAV tables read, by product ID: a UNION query across the 5 value tables for the products on the page.
Where it hurts
Rows and index work grow with every product. On a print catalog I worked on, one product had 707,044 variations and another had 47,233. Each variation was stored as its own simple product, with its own rows in those value tables. The catalog held 1,702,345 products in total, and on production one index, Category Products, took 1 hour 39 minutes to rebuild. The previous team had stopped using configurable products there, Magento's type for one product with selectable options. In the client's words, they caused "huge slow downs when indexing".
Laravel: one row and a JSON column
Laravel has no EAV in the framework. For products whose options vary, one way to store them is a JSON column with Eloquent's AsArrayObject cast. You read and change keys like an array, and save() writes the JSON back.
Once a key becomes a filter, promote it. A MySQL generated column reads the value out of the JSON, and an index on it makes the filter cheap.
Schema::create('products', function (Blueprint $table) { $table->id(); $table->string('sku')->unique(); // paper, finish, binding... $table->json('options'); // promote what you filter on $table->unsignedSmallInteger('paper_gsm') ->virtualAs('options->"$.paper_gsm"')->index(); $table->timestamps(); }); class Product extends Model { protected function casts(): array { return ['options' => AsArrayObject::class]; } } // Product::where('paper_gsm', 130)->get(); one table, one index On MySQL 8, where('paper_gsm', 130) uses that index: EXPLAIN shows products_paper_gsm_index with access type ref. One table, one index, no join.
What you give up
Per-store values are extra work in Laravel. Magento puts a store_id on every value row. In a JSON column you design that yourself, as nested keys per store or as a separate table.
And an attribute an admin can add from the back office is Magento's feature, not Laravel's. In Laravel, a new indexed key still means a migration.
The rule
In Magento, products are EAV whether you'd choose it or not. Leave storefront filtering to the search index, and expect a join for every EAV attribute you filter on in your own code. For your own entities, choose EAV only where admins really add attributes. In Laravel, keep variable options in JSON, and give every key you filter on a generated column with an index.
Next: an index is a cache with a schedule, Magento's indexers next to Laravel Scout.
Where do you draw the line between a JSON key and a real column?
Part 8 of 15 of the Magento 2 vs Laravel series. Originally published on LinkedIn.

