PHPackages                             boukeversteegh/eloquent-relations - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. boukeversteegh/eloquent-relations

ActiveLibrary

boukeversteegh/eloquent-relations
=================================

Eloquent Relationship that defines symmetric relations

02.9kPHP

Since Nov 19Pushed 10y agoCompare

[ Source](https://github.com/boukeversteegh/eloquent-relations)[ Packagist](https://packagist.org/packages/boukeversteegh/eloquent-relations)[ RSS](/packages/boukeversteegh-eloquent-relations/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

EloquentRelations
=================

[](#eloquentrelations)

Adds a new type of relationship to Eloquent (the ORM that Laravel uses) that matches either of two foreign keys.

```
composer require boukeversteegh/eloquent-relations dev-master

```

HasManySymmetric
----------------

[](#hasmanysymmetric)

Eloquent Relationship that defines symmetric relations. Implemented as a HasMany relation with two candidate foreign keys.

The relation is equivalent to the following join:

```
SELECT * FROM parent
JOIN related ON (parent.id = related.foreign_key_1 OR parent.id = related.foreign_key_2)
```

Use cases:

- Friendships (id, inviting\_user\_id, receiving\_user\_id): $user-&gt;friendships
- Messages (id, receiver\_user\_id, sending\_user\_id): $user-&gt;messages
- Games (id, home\_team\_id, away\_team\_id): $team-&gt;games

### Usage

[](#usage)

Use the provided trait to support symmetric relations, and define a relationship.

```
class User extends \Illuminate\Database\Eloquent\Model
{
    use \EloquentRelations\HasManySymmetricTrait;

    public function friendships()
    {
        return $this->hasManySymmetric(Friendship::class, ['inviting_user_id', 'receiving_user_id']);
    }
}
```

```
# Lazy load the relationship
$user = User::find(1);
$user->friendships;

# Eager loading
$user = User::with('friendships')->find(1);
$user->friendships;
```

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/f542ce155282b9be7bfb77b1d83611fb4e19490cb1eacf7749fa351651a817f4?d=identicon)[boukeversteegh](/maintainers/boukeversteegh)

---

Top Contributors

[![boukeversteegh](https://avatars.githubusercontent.com/u/53926?v=4)](https://github.com/boukeversteegh "boukeversteegh (14 commits)")

### Embed Badge

![Health badge](/badges/boukeversteegh-eloquent-relations/health.svg)

```
[![Health](https://phpackages.com/badges/boukeversteegh-eloquent-relations/health.svg)](https://phpackages.com/packages/boukeversteegh-eloquent-relations)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
