dd-developments/laravel-dynamic-relations 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

dd-developments/laravel-dynamic-relations

最新稳定版本:v1.0.1

Composer 安装命令:

composer require dd-developments/laravel-dynamic-relations

包简介

Dynamic, declarative Eloquent relations via maps + resolveRelationUsing.

README 文档

README

dd-developments Hawk Logo

🧩 Laravel Dynamic Relations

Dynamic, declarative & trait-driven Eloquent relations for modern Laravel apps
by dd-developments — Hosted in Belgium 🇧🇪

Version Tests Downloads License Laravel 12 PHP 8.3+

💡 What is Laravel Dynamic Relations?

Laravel Dynamic Relations brings a next-level modularity to your Eloquent models.
Instead of hardcoding relationships like hasMany() or belongsTo(), you can define, register and resolve them dynamically — via traits or config — keeping your models lightweight and flexible.

Think of it as “Eloquent relationships, but hot-swappable.”
Every model can declare its links without being tightly coupled to others.

✨ Key Features

Trait-first design – Attach reusable relationship traits to any model
⚙️ Declarative configuration – Centralize mappings via config/dynamic-relations.php
🧬 Runtime registration – Define relations on-the-fly with DynamicRelations::for()
🧩 All relation types supportedhasOne, hasMany, belongsTo, belongsToMany, and all morphs
🚀 Zero boilerplate – Auto-registered via the Service Provider
🧱 Modular & package-friendly – Ideal for microservice or multi-module Laravel setups
💥 “Everything is hot-swappable” philosophy – Replace, extend, or override any relation dynamically

⚙️ Installation

composer require dd-developments/laravel-dynamic-relations
php artisan vendor:publish --tag=dynamic-relations-config

That’s it. The service provider automatically hooks into Laravel’s boot cycle and enables runtime mapping.
🧬 Example — Trait-Based Relation

Add reusable relationship logic to any model using traits.

use DdDevelopments\DynamicRelations\Facades\DynamicRelations;

trait HasManyImages
{
    protected static function bootHasManyImages(): void
    {
        DynamicRelations::for(static::class, 'images', fn ($model) =>
            $model->morphMany(Image::class, 'imageable'));
    }
}

Then in your model:

use App\Models\Traits\HasManyImages;

class Post extends Model
{
    use HasManyImages;
}

That’s it — no need to touch your Post model’s body again.
Each relation lives in its own modular trait and can be reused across the ecosystem.
🧠 Why this Package Exists

Laravel’s Eloquent ORM is powerful, but static.
Relationships are normally baked directly into models, making code harder to reuse across modules or packages.

Laravel Dynamic Relations fixes that by providing a declarative API and a runtime registration layer, merging the best of both worlds:
config-driven flexibility and trait-based simplicity.
Feature	This Package	Typical Alternatives
Trait-first design	✅	❌
Config-driven maps	✅	⚠️ Partial
Runtime registration (DynamicRelations::for)	✅	❌
Full morph coverage	✅	⚠️
Laravel 12 + Pest v4 support	✅	⚠️
Hot-swappable relations	✅	❌
🧩 Example Config (Optional)

Prefer central control? You can declare all relations from config/dynamic-relations.php:

return [
    App\Models\Post::class => [
        'author' => fn ($m) => $m->belongsTo(App\Models\User::class, 'user_id'),
        'images' => fn ($m) => $m->morphMany(App\Models\Image::class, 'imageable'),
    ],
];

Every time Laravel boots, these are automatically registered — no manual wiring required.
🧰 Ideal Use Cases

    🧩 Modular CMS architectures

    🧱 Multi-tenant or multi-package Laravel setups

    🧪 Package development (shared traits between domains)

    🔁 Dynamic content models (relations change based on config)

    ⚡ Projects embracing “Everything is hot-swappable” philosophy

🧪 Testing Support

This package ships ready for Pest v4 and Orchestra Testbench.
Simply run:

composer test

and you’re good to go.
📜 License

Released under the MIT License
© 2025 dd-developments.com

— All rights reserved.
🧠 Author

Built with 💡 by Daniel Demesmaecker
for dd-development.com

— Hosted in Belgium 🇧🇪

    Everything is hot-swappable.
    Built for modular CMS architectures where every relation is replaceable, extendable, and reusable.

                                          Crafted with precision by dd-development • Innovation through modularity.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-11-02

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固