dimanche 22 avril 2018

How to user Laravel Polymorphism when having existing database with lots of user?

I have a User model in my Laravel app. I'm asked to implement a new user type called BusinessUser. However, instead of creating a new model and duplicating lots of code, I thought why not use Laravel's Polymorphic relations.

I can create a userable User model, similar to this and then I can create RegularUser and BusinessUser that inherit from User.

This solution is much cleaner and DRYer. It'd includes creating two more tables for regular_users and business_users with respective specific columns while having users to save only basic login info like name, email...etc.

So far so good, BUT what about existing user in the database? The clean solution includes dropping some columns from users and adding them to regular_users, so that users only contains what's common between regular and business users and I can't lose data in the production DB.



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2JhwLnn
via IFTTT

Aucun commentaire:

Enregistrer un commentaire