In my laravel 5.2 web app I have the following three tables-
users
id
username
profiles
id
user_id
profile_images
id
profile_id
To outline my scenario- a user can have one profile (one-to-one) and a profile can have many profile images (one-to-many). The models for these tables with the relevant relationship functions are-
User.php
public function profile_images(){
$this->hasManyThrough('App\ProfileImage', 'App\Profile');
}
public function profile(){
return $this->hasOne('App\Profile');
}
Profile.php
public function profile_images()
{
return $this->hasMany('App\ProfileImage');
}
public function user()
{
return $this->belongsTo('App\User');
}
ProfileImage.php
public function profile()
{
return $this->belongsTo('App\Profile');
}
My Problem When I call profile_images() on the User model I only get the user data and only column names back for the profiles and profile_images. No attributes/data are returned even though I have a profile (with matching user_id to my test case) and two profile_images with matching profile_id.
Can you help? I'm assuming it's a problem with my hasManyThrough usage.
Thanks
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire