musamba/red-thread 问题修复 & 功能扩展

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

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

musamba/red-thread

最新稳定版本:1.0.3

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

Latest Version on Packagist Software License Total Downloads

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.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-03-05