/*
Country
-> has many
User
-> has many
Post
-> has many
Comment
*/
class Country extends Model
{
use \Staudenmeir\EloquentHasManyDeep\HasRelationships;
public function comments()
{
return $this->hasManyDeep('App\Comment', ['App\User', 'App\Post']);
}
}
// Access country comments
$country->comments();
我认为这个包可能对你有帮助,
软件包的自述文件说明了各种该包支持的关系类型:
有很多
多对多
MorphMany
MorphToMany
MorphedByMany
属于
以下是复杂关系的 HasMany 关系的自述文件中的示例:
在上面的示例中,该包使用 Eloquent 约定键,并且该包允许您为本地键和外键指定自定义键。