Red Thread is a laravel package that helps you easily list all relationships within a given model.
musamba/red-thread is a Laravel package for red thread is a laravel package that helps you easily list all relationships within a given model..
It currently has 2 GitHub stars and 6 downloads on Packagist (latest version 1.0.3).
Install it with composer require musamba/red-thread.
Discover more Laravel packages by musamba
or browse all Laravel packages to compare alternatives.
Last updated
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.
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"
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.
composer test
Please see CHANGELOG for more information on what has changed recently.
Feel free to contribute to this package and help me to improve it. You can contribute by opening an issue or a pull request.
If you discover a security vulnerability within RedThread, please open an issue.
The MIT License (MIT). Please see License File for more information.