Weave 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

Relationships Laravel Package

stillat/relationships

A Laravel package that streamlines working with model relationships through a fluent, expressive API. It helps define and manage related records, reduce boilerplate, and keep Eloquent models clean and organized.

View on GitHub
Deep Wiki
Context7

Getting Started

Stillat Relationships is an Eloquent relationship helper; reach for it when you need higher-level relationship operations such as reconciling a one-to-many collection without hand-written diff logic. Install with Composer (composer require stillat/relationships) and confirm the service provider is auto-discovered; if the README requires publishing config or adding a trait to models, do that before using sync helpers. Look first at the one-to-many sync documentation and tests, because v2.4.0 specifically fixes one-to-many syncing. A good first use case is a Team hasMany Members or Post hasMany Comments list where the UI submits the desired child IDs: wrap the package sync in a transaction, refresh the relation, and assert foreign keys in a feature test. Upgrade to ^2.4 if one-to-many sync is part of your workflow.

Implementation Patterns

  • Keep normal Eloquent relationship definitions as the source of truth; use the package for higher-level associate/dissociate/sync operations.
  • Put sync calls in an action or service class: authorize, validate IDs, open a transaction, sync, refresh the relation, then return the model.
  • Use it for ordered child collections; if order matters, update position columns after syncing and reload the relationship.
  • Use associate/dissociate for single-parent changes; for many-to-many, prefer Laravel’s native sync unless the package wrapper gives you needed consistency.
  • Lock parent or child rows when concurrent requests can sync the same collection; pair with database transactions, foreign keys, and unique constraints.
  • Test with RefreshDatabase: no-op sync, add, remove, and mixed changes. Assert child foreign keys, absence of detached rows, and relation counts using factories and assertDatabaseHas.

Gotchas and Tips

  • v2.4.0 is a bugfix release for one-to-many syncing; pin >=2.4.0 and re-test any custom workaround you built for the old behavior.
  • Confirm sync semantics in the docs: does it detach, null the foreign key, or delete children? Soft deletes and global scopes can hide children from sync calculations.
  • Mass sync may bypass model events and observers; if you rely on auditing or cascade side effects, dispatch those manually or sync individually.
  • Watch foreign key constraints, nullable foreign keys, morph types, and composite keys; add explicit tests for these cases.
  • If the package publishes config, run php artisan config:clear after changes. Debug with toSql, DB::listen, assertDatabaseHas, and withoutGlobalScopes to reveal hidden rows.
  • Keep the Composer constraint at ^2.4; prefer extending via your own action classes around package calls rather than editing vendor code.
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.
elmogy/larafast
xeviant/laravel-paystack
gorilladash/laravel-website-sdk
martialbe/flysystem-oss
chondal/3312client
jeroen-g/flickr
opscale-co/nova-genbi
itsjustvita/laravel-retention
tequilarapido/trackit
gregsphotography/site-builder-filament
cabaoctavio/laravel-query-log
gregsphotography/site-builder-components
io-digital/clickatell
snowsoft/laravel-admin
oxygen/auth
relicsoftware/barakah-payment-gateway
tobya/work-with-composer
equipc/laravel-email-validator
equipc/laravel-email-database-log
adedsec/nova-translated-labels