korridor/laravel-has-many-sync
hasMany relationships without manual detaching/attaching, reducing boilerplate and improving maintainability.sync method naming), minimizing disruption to existing patterns.User → Roles, Post → Tags).belongsToMany is already optimal.1.* branch), ensuring broad adoption.Korridor\HasManySync\HasSyncable), avoiding conflicts.hasMany behavior (no support for custom hasManyThrough or polymorphic relationships).syncing, synced).detach()->attach() for large datasets? Are there benchmarks?User → Posts → User) handled?DELETE + INSERT query, or multiple? Impact on indexes?1.* branch handle all hasMany use cases, or are there gaps?belongsToMany (though redundant for true M:M relationships).hasMany relationships (e.g., Post → Comments).detach()->attach() with sync() in a single controller/method.EXPLAIN ANALYZE).1.* branch and alias the namespace in composer.json:
"extra": {
"aliases": {
"korridor/has-many-sync": "korridor/laravel-has-many-merged"
}
}
hasMany table structure (no custom pivot tables or intermediate models).with() queries). Ensure cache drivers are configured to handle dynamic data.SyncHasManyJob::dispatch($parent, $children);
composer require korridor/laravel-has-many-sync
HasSyncable trait to parent models:
use Korridor\HasManySync\HasSyncable;
class Post extends Model {
use HasSyncable;
// ...
}
$post->comments()->detach($commentIdsToRemove);
$post->comments()->attach($newCommentIds);
With:
$post->syncComments($newCommentIds);
dd($model->getSyncableRelationship()) to verify relationship metadata.DELETE + INSERT query per sync (O(n) for n children).$post->syncComments(array_chunk($ids, 100));
| Scenario | Impact | Mitigation |
|---|---|---|
| Database timeout | Partial sync | Wrap in transactions or queues. |
| Invalid child IDs | Silent failure | Validate input arrays. |
| Circular dependencies | Infinite loop | Add depth checks in custom logic. |
| Missing indexes | Slow queries | Ensure FK indexes exist. |
| PHP memory limits | OutOfMemoryException | Use smaller batches. |
sync() vs. attach()/detach().delete constraints).How can I help you explore Laravel packages today?