Your code looks fine. Show us the query you are using to get the profiles. The first and most important issue with this approach is that if you are querying it like :
User::with('profile')->get();
you will not get the profiles at all as the plain User
class does not have type
set yet. So eager loading will not work correctly. You can either create a scope method and explicitly set model type to something, but this way it will also work only partially. I would suggest to create two methods - userProfile
and corporateProfile
this way you eager load with ('userProfile', 'corporateProfile')
and depending on the user type one of the relations will just stay empty.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community