panakour/laravel-eloquent-relationships

以编程方式获取 Laravel Eloquent 关联。

v0.0.1 2023-03-09 09:29 UTC

This package is auto-updated.

Last update: 2024-09-16 17:32:14 UTC


README

tests Code Coverage Badge

这可以让您以编程方式获取 Laravel 中模型的关联,以便按需使用。

示例

use EloquentRelationships\RelationMethods;
use EloquentRelationships\Relations;

$relations = new Relations(new YourModel());

//get all relations
$collection = $relations->all();

//or get relations by method

//belongsToMany
$collection = $relations->getByMethod(RelationMethods::BelongsToMany->value);

//MorphedByMany
$collection = $relations->getByMethod(RelationMethods::MorphedByMany->value);