public function comment()
{
return $this->hsaMany(Comment::class, 'user_id', 'id');
}
【laravel的学习|laravel5.6框架模型关联】在模型关联中,如上例子,如果关联的外键是以当前模型名加id的形式,内键是id,那么这两者都可以省略,变成如下的形式
public function comment()
{
return $this->hasMany(Comment::class);
}
public function comment()
{
return $this->hsaMany(Comment::class, 'user_id', 'id');
}
public function comment()
{
return $this->hasMany(Comment::class);
}