板 / 关系
从给定的 Laravel 模型中提取关系
1.0.0
2023-02-10 20:02 UTC
Requires
- php: ^8.1
- illuminate/contracts: ^9.0
- spatie/laravel-package-tools: ^1.14.0
Requires (Dev)
- laravel/pint: ^1.0
- nunomaduro/collision: ^6.0
- nunomaduro/larastan: ^2.0.1
- orchestra/testbench: ^7.0
- pestphp/pest: ^1.21
- pestphp/pest-plugin-laravel: ^1.1
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
- phpunit/phpunit: ^9.5
- staudenmeir/belongs-to-through: ^2.12
This package is auto-updated.
Last update: 2024-08-29 11:48:26 UTC
README
该包旨在使用反射和返回类型检查从给定的模型中提取 Eloquent 关系。
安装
您可以通过 composer 安装此包
composer require plank/larelations
用法
给定一个 Eloquent 模型实例或其类字符串,此包将提取模型上定义的所有关系,并以 RelationInstance
项的集合形式返回。
每个 RelationInstance
都有一个定义关系的反射方法 ($method
) 以及一个 Relation
(关系) 实例。在 RelationInstance
上有一些辅助方法,允许您分类关系的类型(例如,子关系、父关系、交叉关系等)。
$extractor = new \Plank\Larelations\Extractor(); $instances = $extractor->extract($post); $instances = \Plank\Larelations\Facades\Larelations::extract(Post::class); foreach ($instances as $instance) { if ($instance->isChild()) { // Handle child types of relations } if ($instance->relation instanceof \Znck\Eloquent\Traits\BelongsToThrough) { // Handle custom relation } // The method property is the \ReflectionMethod of the relation instance $instance->method->getName(); // posts }
测试
composer test
贡献
有关详细信息,请参阅 CONTRIBUTING
致谢
许可协议
MIT 许可协议(MIT)。有关更多信息,请参阅 许可文件
安全漏洞
如果您在 Larelations 中发现安全漏洞,请发送电子邮件至 security@plankdesign.com。所有安全漏洞都将得到及时处理。