I have two model like this:
User:
id - username
Image:
id - img - user_id
each user has many images. so it sounds I should use hasMany relation .
I know how can I use if I have a list of users. now how can I show a list of images by usernames :
list of images :
img - username
in User model :
public function image()
{
return $this->hasMany('Image');
}
in Image model:
public function user()
{
return $this->belongsTo('User');
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire