I hope someone can help me with my Database Design. I have a table customers where all customers are stored, while they can be of a different type. The type would be "client" or "lead", indicating if it is a actual customer or just a lead.
Now i need a unique CustomerId that is auto-incrementing but only for clients and not for leads. I can't take the id since that value is incrementing for clients and leads.
Did someone solve a similar issue before and give me a approach to getting a incrementing customer-number?
@Lampone - I would create two tables, one for Customers and one for Leads and then in you application if a lead becomes upgraded to a customer you can codd the logic.
You are still going to need an id on each record in your database as this is how each record is uniquely identified.
@D9705996 It was my first idea, but they have so many relations in common and both store the same data in the table. It felt kind of wrong to have 2 tables.
I agree with @Lampone, but in case you need the different type of users in the same table, I would create a UserObserver and in the created method update your auto-increment field (just if the user is of type client) with the count of all client users (withTrashed to avoid duplicated fields when restoring deleted clients).
To do something like this without being gross you can use this package https://github.com/tightenco/parental because it let you manage easy different type of users using Single Table Inheritance.
Single Table Inheritance is what I used until now (without knowing the name :) )
@globals thanks for package suggestion
I didn't want to use the manual incrementing field, because I would like to be able to delete leads permanently. Since the gdpr is in effect I would rather be safe than sorry.
Maybe @D9705996 suggestion with a related model to store the status (client/lead) could work. Trying to wrap my head around it...
@Lampone - not having an incrementing id will not help you with GDPR compliance as the personally identifiable information is still stored in your database. To be honest GDPR is an absolute minefield.
You might want to look at some laravel specific GDPR packages that help with anonymising data e.g.
With GDPR If you are not sure take expert advice as the penalties for non compliance are severe, and I don't mean asking here - find a reputable specialist online.