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

cristian9509's avatar

INSERT record in Supertype/Subtype tables

I have this schema. Image

My employees and customers share the same users table. A user can be either an employee or a customer.

How do I INSERT a user record and also make sure to insert in the right (subtype) table which in this case can be employees or customers?

  1. Implement logic in Eloquent Models? like (for example inserting an employee record): Insert values into users; Check the user_type; If user_type = emp then insert the specific values into employees table;

  2. Use MYSQL triggers, stored procedures? (I am not very familiar with them)

What about when my employees could also have subtypes associated to them and need extra fields in different tables (employee_types: sales, acquisitions, managers, etc)?

0 likes
1 reply
dammr's avatar

Have you look at polymorphic relations on eloquent?

Please or to participate in this conversation.