Support the ongoing development of Laravel.io →
posted 9 years ago
Eloquent
Last updated 2 years ago.
0

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.

0

Sign in to participate in this thread!

Eventy

Your banner here too?

mrfoh mrfoh Joined 25 Feb 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.