邮政型号如何从关系中检索数据?
class Post extends Model
{
public function comments()
{
return $this->hasMany('App\Comment');
}
public function users()
{
return $this->belongsTo('App\User');
}
评论模型
class Comment extends Model
{
public function posts()
{
return $this->belongsTo('App\Post');
}
}
用户模型
class User extends Model
{
public function posts()
{
return $this->hasMany('App\Post');
}
现在我的问题是我怎么可以访问属于后所有评论评论ed用户名 谢谢你提前
仅具有用户名你只能够得到所有评论所有帖子归特定用户所有,为此你可以使用hasManyThrough关系 – zakius
@ zakius.thank你的评论。你发布你的答案 – iCoders
试试这个'user :: with('post.comment') - > get()' – mdamia