musamba/red-thread
Composer 安装命令:
composer require musamba/red-thread
包简介
Red Thread is a laravel package that helps you easily list all relationships within a given model.
README 文档
README
RedThread is a simple package that allows you to list your Laravel models relationships.
The two people connected by the red thread are destined lovers, regardless of place, time, or circumstances. This magical cord may stretch or tangle, but never break.
Table of Contents
Installation
You can install the package via composer:
composer require musamba/red-thread
You can publish the config file with:
php artisan vendor:publish --tag="red-thread"
Usage
You simply need to use the HasRedThreads trait in your model and call the relationships method.
Here is an example:
use Musamba\RedThread\Traits\HasRedThreads; use Musamba\RedThread\Attributes\RedThread; class Book extends Model { use HasRedThreads; // ... #[RedThread] public function reviews(): HasMany { return $this->hasMany(Review::class); } #[RedThread] public function author(): BelongsTo { return $this->belongsTo(Author::class); } // ... }
Calling the provided relationships() static method on a model instance:
Book::relationships();
An array containing all the relationships will be returned.
[
'reviews' => 'Illuminate\Database\Eloquent\Relations\HasMany',
'author' => 'Illuminate\Database\Eloquent\Relations\BelongsTo',
]
If the check_for_attribute configuration key is set to false, the package will check the return type of the method,
so having a situation like this:
use Musamba\RedThread\Traits\HasRedThreads; class Book extends Model { use HasRedThreads; // ... public function reviews(): HasMany { return $this->hasMany(Review::class); } public function author(): BelongsTo { return $this->belongsTo(Author::class); } // ... }
The same array as above will be returned.
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Feel free to contribute to this package and help me to improve it. You can contribute by opening an issue or a pull request.
Roadmap
- Add artisan command to list relationships via CLI.
- Add related model class and foreign key information.
Security Vulnerabilities
If you discover a security vulnerability within RedThread, please open an issue.
Credits
License
The MIT License (MIT). Please see License File for more information.
musamba/red-thread 适用场景与选型建议
musamba/red-thread 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6 次下载、GitHub Stars 达 2, 最近一次更新时间为 2024 年 03 月 05 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「models」 「Relationships」 「eloquent」 「musamba」 「red-thread」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 musamba/red-thread 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 musamba/red-thread 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 musamba/red-thread 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
PHP Interface for Babel Street Text Analytics
Wordpress Query Builder class library for custom models and data querying.
Adds nested resources routing support along with related actions and relationship handlers to the Yii RESTful API framework
Adds KeyBy('id') to Eloquent relationships
A Laravel package for managing model drafts.
A package to better handle database operations via Eloquent Models.
统计信息
- 总下载量: 6
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 23
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-03-05