what is your though about using this for everything : Schema::create('addresses', function (Blueprint table) {
table->id();
table->string('type')->default('shipping'); // shipping | billing
table->string('last_name')->nullable();
table->string('email')->nullable();
table->string('state', 100)->nullable();
table->string('postcode', 20)->nullable();
table->string('address_line2')->nullable();
table->timestamps();
$table->softDeletes();
});
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Pretty clean migration! 🎉
A single, polymorphic addresses table like this is a nice “one-ring-to-rule-them-all” approach, but it comes with a few trade-offs. Here’s how I usually think it through.
👍 What works well
One source of truth
• No duplicated address tables all over the codebase.
• Every model just adds morphOne / morphMany and we’re done.
Historical snapshots
Because the address row is copied onto the order (instead of a foreign-key to a customer’s current address) you can freeze shipping info exactly as it was at checkout.
Simple migrations / maintenance
When you need a new column (e.g. “company”), you add it once.
Flexibility for any “addressable” model
Users, orders, warehouses, suppliers, returns, invoices… whatever.
🤔 Things to think about before using it “for everything”
Area
Why it might bite you
Possible mitigation
Validation differences
A user’s profile address might allow “nicknames”, an order address probably shouldn’t.
Put context-specific validation in FormRequests / DTOs instead of relying on DB schema.
Data integrity
Polymorphic relations don’t enforce foreign-key constraints, so “dangling” addresses are easy to create.
Scheduled job that deletes orphaned rows, or move to “constrained morphs” in Laravel 10.
Performance / indexing
Millions of addresses jammed into a single table can get slow if you query by addressable_type a lot.
Composite index (addressable_type, addressable_id, type). Partitions if it really explodes.
Multi-tenant / GDPR “right to be forgotten”
Harder to physically delete all data for a tenant or user when everything is in one table with different owners.
Keep deleted_at, but still consider logical sharding per tenant for large SaaS.
Different shapes of addresses per country
Japan vs US vs NL all have different “lines” and post code rules.
Keep the table generic but push country-specific logic to frontend / service layer; or store a json blob for exotic formats.
Lat / Lng in meta
You lose the ability to index & geo-query easily when coords are in JSON.
Promote lat and lng to DECIMAL(10,7) columns if you need radius searches.
“Shipping” vs “Billing” vs “Contact”
A simple type string works… until an order needs both a shipping and a billing address at the same time.
Either allow multiple rows per order (morphMany) or switch to an enum + composite unique constraint (addressable_id, addressable_type, type).
• If you stay with the JSON meta, add a ->nullable()->comment('{"lat":..., "lng":..., ...}') for clarity.
• Consider a lookup table for countries / states for referential integrity.
• Soft-deletes are perfect for keeping old addresses around without cluttering normal queries.
🚀 When would I not use the single polymorphic table?
B2B systems where a “location” has 40+ attributes (opening hours, tax jurisdiction, warehouse capacity…). That smells like its own entity.
Extremely high write/read traffic on order addresses only – you might split off an order_addresses table to keep indexes smaller.
Cases where you must enforce FK constraints in the DB layer (e.g. financial apps subject to audits).
🎯 TL;DR
• For most e-commerce / SaaS apps, this table is perfectly fine and keeps life simple.
• Make sure you add the right indexes, use strong validation, and be conscious of future “address shapes”.
• When the address becomes more than an address (geo-search, logistics hub), don’t be afraid to break it into a dedicated model later.
Hope that helps you decide whether to go all-in on the polymorphic route! If you’ve got a particular edge case in mind, throw it at me and we’ll stress-test the design together. 😉