It's hard to understand your setup. Better show the tables, models or just the relations involved, then what you exactly want to achieve.
True...
User Model:
public function userable() {
return $this->morphTo();
}
This is a polymorphic relation to various other models, eg 'UserFirm' the userfirm model contains various extra data specific to that type of user, including a hasOne relationship to a firm
UserFirm:
public function user() {
return $this->morphOne('User', 'userable');
}
public function firm(){
return $this->hasOne('Firm', 'id', 'firm_id');
}
Then finally, the UserFirm model relates to a Firm Model
Firm:
public function userfirms(){
return $this->hasMany('UserFirm');
}
using this setup, I can go to a firm, and then return a list of the 'userfirms' that belong to it, then get the 'user' for each firm 'userfirm', but i'd like to just return a list of users that belong to a firm
$userfirms = $this->hasMany('UserFirm')->get();
foreach ($userfirms as $userfirm){
print $userfirm->user->first_name;
}
the above code works, but I want to return an object all all the 'user' data to the template, without having to loop through and get each user out of the database..
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community