PHPackages                             tassawartech174/mongodb-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. [Database &amp; ORM](/categories/database)
4. /
5. tassawartech174/mongodb-relations

ActiveLibrary[Database &amp; ORM](/categories/database)

tassawartech174/mongodb-relations
=================================

Custom Laravel Eloquent relationships for MongoDB using jenssegers/mongodb and mongodb/laravel-mongodb. Supports unidirectional many-to-many and reverse lookups for embedded and reference-based relations.

v1.1.5(11mo ago)0911MITPHPPHP &gt;=7.4

Since Jun 29Pushed 11mo agoCompare

[ Source](https://github.com/tassawartech174/mongodb-relations)[ Packagist](https://packagist.org/packages/tassawartech174/mongodb-relations)[ RSS](/packages/tassawartech174-mongodb-relations/feed)WikiDiscussions main Synced 3w ago

READMEChangelogDependencies (1)Versions (13)Used By (0)

MongoDB Relations for Laravel
=============================

[](#mongodb-relations-for-laravel)

[![License: MIT](https://camo.githubusercontent.com/08cef40a9105b6526ca22088bc514fbfdbc9aac1ddbf8d4e6c750e3a88a44dca/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d626c75652e737667)](LICENSE)

Custom unidirectional many-to-many relationship support for MongoDB in Laravel.

---

📦 Installation
--------------

[](#-installation)

```
composer require tassawartech174/mongodb-relations
```

**Requires PHP 7.4+ and Laravel 6.x – 11.x.**

---

⚙️ Configuration
----------------

[](#️-configuration)

If you want to customize the default local key used in relations, publish the package config file:

```
php artisan vendor:publish --provider="TassawarTech174\MongodbRelations\MongodbRelationsServiceProvider" --tag=mongodb-relations-config
```

Or use this command:

```
php artisan vendor:publish --tag=mongodb-relations-config
```

- This will publish:

```
config/mongodb-relations.php
```

---

🚀 Usage
-------

[](#-usage)

**Step 1: Use the Trait**

In your Eloquent model (e.g. `User`), use the provided trait:

```
use TassawarTech174\MongodbRelations\Traits\MongodbRelations;

class User extends Model
{
    use MongodbRelations;

    public function roles()
    {
        return $this->manyToManyRelation(Role::class, 'role_ids');
    }
}
```

Or use relation like:

```
use TassawarTech174\MongodbRelations\Traits\MongodbRelations;

class User extends Model
{
    use MongodbRelations;

    public function roles()
    {
        return $this->manyToManyRelation(Role::class);
    }
}
```

**Step 3: Relationship Methods**

- Get related models:

```
$user->roles;
```

- Attach related models:

```
$user->roles()->attach(['id1', 'id2']);
```

- Detach related models:

```
$user->roles()->detach(['id1']);
```

- Sync related models:

```
$user->roles()->sync(['id1', 'id3']);
```

- Models where relations:

```
$user->whereRelationField('roles', 'name', 'operater', 'search value);

$user->orWhereRelationField('roles', 'name', 'operater', 'search value);
```

---

✅ Supported Laravel Versions
----------------------------

[](#-supported-laravel-versions)

- Laravel 6.x
- Laravel 7.x
- Laravel 8.x
- Laravel 9.x
- Laravel 10.x
- Laravel 11.x

🔐 License
---------

[](#-license)

This package is open-source software licensed under the MIT license.

###  Health Score

31

—

LowBetter than 66% of packages

Maintenance50

Moderate activity, may be stable

Popularity12

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity44

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 98.2% 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.

###  Release Activity

Cadence

Every ~1 days

Total

12

Last Release

354d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6fbf2b9ccd0c856609e018681bdb257ad3bd680cbb06d5ec1f525593eb3820d3?d=identicon)[tassawartech174](/maintainers/tassawartech174)

---

Top Contributors

[![tassawartech174](https://avatars.githubusercontent.com/u/53806824?v=4)](https://github.com/tassawartech174 "tassawartech174 (55 commits)")[![tassawar-ascend](https://avatars.githubusercontent.com/u/167427055?v=4)](https://github.com/tassawar-ascend "tassawar-ascend (1 commits)")

---

Tags

laraveleloquentmongodbmany to manyRelationshipscustom relationsreverse relation mongodbunidirectional relationship

### Embed Badge

![Health badge](/badges/tassawartech174-mongodb-relations/health.svg)

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

###  Alternatives

[mongodb/laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel

7.1k8.0M87](/packages/mongodb-laravel-mongodb)[kirschbaum-development/eloquent-power-joins

The Laravel magic applied to joins.

1.6k29.9M42](/packages/kirschbaum-development-eloquent-power-joins)[cybercog/laravel-love

Make Laravel Eloquent models reactable with any type of emotions in a minutes!

1.2k322.4k1](/packages/cybercog-laravel-love)[timgws/query-builder-parser

Build complex Eloquent &amp; QueryBuilder queries automatically when using jQuery-QueryBuilder

161399.7k](/packages/timgws-query-builder-parser)[reedware/laravel-relation-joins

Adds the ability to join on a relationship by name.

2121.2M16](/packages/reedware-laravel-relation-joins)[illuminatech/sync-many-attribute

Allows control over Eloquent many-to-many relation via array attribute

156.7k](/packages/illuminatech-sync-many-attribute)

PHPackages © 2026

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