I have a UserProfile model with associated table 'user_profiles' that has some fields like 'name', 'user_id', 'contact'. In the model there is a function which retrieves this data with the Eloquent ORM and adds an additional property 'provinces' to it before returning the profile object.
class UserProfile extends Eloquent {
//....preceding methods ommitted
public function totalProfile($userid) {
$profile = $this->find($userid);
$profile->provinces = Province::all();
return $profile;
}
}
When I call the above function from my UserProfilesController it returns the profile with no problem, but when I try to call the method from my PagesController it just returns empty, like so:
class PagesController extends \BaseController {
public function __contstruct(UserProfile $userProfile) {
$this->userProfile = $userProfile;
}
public function show($id) {
print_r($this->userProfile->totalProfile($id)); //prints nothing
die;
}
}
I would really appreciate it if someone could help explain why this is? Thank you very much!