Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Eloquent Has Many Deep Contracts Laravel Package

staudenmeir/eloquent-has-many-deep-contracts

Contracts for staudenmeir/eloquent-has-many-deep. Includes the ConcatenableRelation contract to make third-party relationship packages concatenable with HasManyDeep, improving interoperability when combining deep Eloquent relations.

View on GitHub
Deep Wiki
Context7

Getting Started

This package provides only interfaces—no concrete implementation. Start by installing it via Composer:

composer require staudenmeir/eloquent-has-many-deep-contracts

Then locate the primary contract: Staudenmeir\EloquentHasManyDeep\Contracts\HasManyDeepContract. This interface defines the minimal contract for deep hasMany relationships (e.g., Post → User → Comments). Use it to type-hint in your own classes or test doubles.
First use case: Type-hint the contract in your repository or service classes to accept any implementation of HasManyDeep, e.g., HasManyDeep, HasManyDeepThroughPivot, etc.

Implementation Patterns

  • Type-hint in constructors/services: Inject a HasManyDeepContract to accept multiple implementations (e.g., for testing or futureSwap).
    public function __construct(protected HasManyDeepContract $postsWithComments) {}
    
  • Abstraction layer for deep relations: Create your own PostRepository that accepts contracts, letting you swap implementations (e.g., native HasManyDeep, custom caching wrapper) without breaking consumers.
  • Testing mocks: Use the contract to mock deep relationships in unit tests with Mockery::mock(HasManyDeepContract::class).
  • Package development: Define your package’s public API in terms of HasManyDeepContract to ensure compatibility with community implementations (e.g., staudenmeir/eloquent-has-many-deep, future forks, or internal variants).

Gotchas and Tips

  • No runtime behavior: This package is purely contractual—it doesn’t add new functionality. Ensure you’re also using an implementation package (e.g., staudenmeir/eloquent-has-many-deep) in your app.
  • Versioning alignment: Check that your implementation package version matches the contract interface version. Mismatches may occur if the contract evolves and you’re pinned to an older version.
  • Laravel’s auto-resolution: Since this is only interfaces, Laravel can’t resolve concrete instances from them. Always bind implementations in AppServiceProvider if injecting the contract:
    $this->app->bind(HasManyDeepContract::class, HasManyDeep::class);
    
  • Testability win: The real value surfaces in integration points—e.g., when building an admin panel or API that should support both deep and shallow relations. Use the contract to abstract over relationship resolution.
  • Document assumptions: When relying on the contract, clearly document expected behavior (e.g., "this relation supports query constraints like where and with") since the interface alone doesn’t enforce them.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport