郵政型號如何從關係中檢索數據?
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