承接 tassawartech174/mongodb-relations 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

tassawartech174/mongodb-relations

最新稳定版本:v1.1.5

Composer 安装命令:

composer require 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.

README 文档

README

License: MIT

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

📦 Installation

composer require tassawartech174/mongodb-relations

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

⚙️ 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

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

  • Laravel 6.x

  • Laravel 7.x

  • Laravel 8.x

  • Laravel 9.x

  • Laravel 10.x

  • Laravel 11.x

🔐 License

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

统计信息

  • 总下载量: 79
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-06-29