he eloquent-has-many-deep package by Jonas Staudenmeir allows Eloquent HasManyThrough relationships with unlimited levels. It supports many-to-many and polymorphic relationships and all their possible combinations.
The package's readme illustrates various types of relationships that this package supports:
- HasMany
- ManyToMany
- MorphMany
- MorphToMany
- MorphedByMany
- BelongsTo
Here's an example from the readme of a HasMany relationship for a complex relationship:
/* 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();
In the above example, the package uses Eloquent conventions keys, and the package allows you to specify custom keys for local and foreign keys.
0 comments:
Post a Comment
Thanks