Hello folks. I have a "architecture" question about an online store. A friend of mine wants me to build him an online store for mechanical parts. I chose to do it with Laravel/Nuxt 3 combo because of my previous experience with Vue. So far so good. The conundrum I find myself in is in regards to "customer" registration. More specifically what is the better way to handle when a individual wants to register on behalf of a firm/company.
My initial idea is to have User and Company models and a polymorphic model Customer which I will use as the AUTH_MODEL. On the front-end I will have some extra fields if the person doing the registration opts for company registration - company name, address, vat number etc. BUT do I keep single "user" tied to a single "company" or do somehow allow later on other individuals to register on behalf of the same already existing company while still having single Customer polymorphic relationship? What is considered best practice in this kind of scenarios?
I am looking forward to hear your advice.
Have a nice day!
do I keep single "user" tied to a single "company" or do somehow allow later on other individuals to register on behalf of the same already existing company while still having single Customer polymorphic relationship?
Well this is a business logic question, not a technical problem. Unfortunately, you need to decide whether you expect multiple users to be able to be assigned to a company or not. Once you have decided, that will then inform you which approach you need to take: whether company name etc is just a field in a customer profile, or whether you need to extract “company” to its own model, and create a many-to-many relation between users and companies (a polymorphic relation isn’t needed here and not sure why you mentioned it).
Further to Martin's sound advice, do customers even need to login? What will they do?
Do orders that are for the same company need to be seen together? queried together?
If I sign up today and say I am from Abc Limited and John Doe signs up tomorrow and says he is also from Abc Limited, how do you know either of us is telling the truth? How can you determine that we are infact from the same company?
Unless you have a need to collect these together under a single company record, I would make company one line of the delivery address.
Thanks for the replies guys. As I said a friend of mine asked me to help him make a online store. First let me give some more backstory. He is working in a firm that deals in parts for hydraulic systems. He decided that he can make his own company and start selling such products himself. From what he told me he is expecting most of his "clients" to be engineers or representatives of other companies. For that and to be complaint with everything regulation wise etc (especially in Germany) he needs the company official address, registered legal name, vat number and few other things.
That's why i created separate Company model that will hold all that extra info. Since its my first time dealing with companies (legal entities) in Laravel I wanted to hear some opinions how to proceed - do I allow more than 1 individual to be tied to the same company or 1 user - 1 company (even if there are db duplicates in company table). The idea for the polymorphic model "Customer" was as follows - first to hold info that's not specific for user or company. Second - if I go for multiple users - 1 company to have the logic for them to purchase stuff for that exact company.
So at the end of the day just wanted to know whats considered better approach/ best practice or industry standard or whatever you want to call it. Looking forward for more insign in such scenarios if there's any.
Since its my first time dealing with companies (legal entities) in Laravel I wanted to hear some opinions how to proceed - do I allow more than 1 individual to be tied to the same company or 1 user - 1 company (even if there are db duplicates in company table).
@Simomir Again, this is a business decision, not a technical decision, and one you need to make.
The idea for the polymorphic model "Customer" was as follows - first to hold info that's not specific for user or company. Second - if I go for multiple users - 1 company to have the logic for them to purchase stuff for that exact company.
I have no idea what you‘re describing here. A polymorphic model isn’t needed. At all. You would just have a Company model, and then a many-to-many relation with a user or customer model if you did decide multiple users/customers could be associated with a company. There’s absolutely zero need for a polymorphic relation here.
A user could instigate a new account, and then be responsible for all the company details, but then you would need an invite system if they need other users on that account.
Thanks for the replies guys. So I will think about should I make an invite system or not. About the polymorphism - Its not a thing Iam sticking to. Was just an idea and from what you said I will ditch it. About the overall decision 1 or multiple users per company just wanted to see if there's a rule of thumb sort of speak and what other people went for.
Btw is there a suitable package for an invite system just so I dont go and try to invent the wheel all over again?