PHPackages                             plank/larelations - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. plank/larelations

ActiveLibrary[Database &amp; ORM](/categories/database)

plank/larelations
=================

Extract the relations from a given Laravel model

1.0.0(3y ago)635[2 PRs](https://github.com/plank/larelations/pulls)MITPHPPHP ^8.1

Since Feb 10Pushed 2y ago2 watchersCompare

[ Source](https://github.com/plank/larelations)[ Packagist](https://packagist.org/packages/plank/larelations)[ Docs](https://github.com/plank/larelations)[ RSS](/packages/plank-larelations/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (13)Versions (7)Used By (0)

Larelations
===========

[](#larelations)

[![Laravel Version Support](https://camo.githubusercontent.com/f7671270bcb4572612cf17c11b754f1d7d60a75bf5eaf9380ba44ba7b0c9e3a7/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c61726176656c2d392e782c25323031302e782d2532333366613238313f6c6f676f3d6c61726176656c266c6f676f436f6c6f723d253233666666)](https://camo.githubusercontent.com/f7671270bcb4572612cf17c11b754f1d7d60a75bf5eaf9380ba44ba7b0c9e3a7/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c61726176656c2d392e782c25323031302e782d2532333366613238313f6c6f676f3d6c61726176656c266c6f676f436f6c6f723d253233666666)[![GitHub Workflow Status](https://camo.githubusercontent.com/7549b36df2075d0edd2bae2f5a2ff1b4972b599c0cd4d085a6c88c1a026f4e43/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f706c616e6b2f6c6172656c6174696f6e732f72756e2d74657374732e796d6c3f6272616e63683d6d61696e2626636f6c6f723d253233336661323831266c6162656c3d72756e2d7465737473266c6f676f3d676974687562266c6f676f436f6c6f723d253233666666)](https://github.com/plank/larelations/actions?query=workflow%3Arun-tests)[![Code Climate coverage](https://camo.githubusercontent.com/ffabed456ac16ffe95846eb06fdf9c8943a6ea2f6e388fd4a748ec637e13f19b/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636c696d6174652f636f7665726167652f706c616e6b2f6c6172656c6174696f6e733f636f6c6f723d253233336661323831266c6162656c3d74657374253230636f766572616765266c6f676f3d636f64652d636c696d617465266c6f676f436f6c6f723d253233666666)](https://codeclimate.com/github/plank/larelations/test_coverage)[![Code Climate maintainability](https://camo.githubusercontent.com/cb1cd689d25cea41cfb93784bda36c6c2aa8a89aaad636c304d428be70f0fc7b/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636c696d6174652f6d61696e7461696e6162696c6974792f706c616e6b2f6c6172656c6174696f6e733f636f6c6f723d253233336661323831266c6162656c3d6d61696e7461696e61626c696c697479266c6f676f3d636f64652d636c696d617465266c6f676f436f6c6f723d253233666666)](https://codeclimate.com/github/plank/larelations/maintainability)

This package is designed to extract Eloquent Relations from a given Model using reflection and return type checking.

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require plank/larelations
```

Usage
-----

[](#usage)

Given an instance of an Eloquent Model or its class-string, this package will extract all relations defined on the model, and return them in a Collection of `RelationInstance` items.

Each `RelationInstance` has the ReflectionMethod (`$method`) where the relation was defined, as well as an instance of the `Relation` ($relation). There are some helper methods on the `RelationInstance` that allow you to classify the type relation it is (ie. child, parent, pivotted, etc).

```
$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
}
```

Testing
-------

[](#testing)

```
composer test
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Credits
-------

[](#credits)

- [Kurt Friars](https://github.com/kfriars)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

If you discover a security vulnerability within Larelations, please send an e-mail to . All security vulnerabilities will be promptly addressed.

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 97.2% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

1191d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/108450?v=4)[Plank](/maintainers/Plank)[@plank](https://github.com/plank)

---

Top Contributors

[![kfriars](https://avatars.githubusercontent.com/u/3378675?v=4)](https://github.com/kfriars "kfriars (35 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")

---

Tags

laravelplanklarelations

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/plank-larelations/health.svg)

```
[![Health](https://phpackages.com/badges/plank-larelations/health.svg)](https://phpackages.com/packages/plank-larelations)
```

###  Alternatives

[dyrynda/laravel-model-uuid

This package allows you to easily work with UUIDs in your Laravel models.

4802.8M8](/packages/dyrynda-laravel-model-uuid)[spatie/laravel-model-flags

Add flags to Eloquent models

4301.1M1](/packages/spatie-laravel-model-flags)[clickbar/laravel-magellan

This package provides functionality for working with the postgis extension in Laravel.

423715.4k1](/packages/clickbar-laravel-magellan)[spatie/laravel-sql-commenter

Add comments to SQL queries made by Laravel

1931.4M1](/packages/spatie-laravel-sql-commenter)[spatie/laravel-deleted-models

Automatically copy deleted records to a separate table

409109.8k4](/packages/spatie-laravel-deleted-models)[wnx/laravel-backup-restore

A package to restore database backups made with spatie/laravel-backup.

203330.1k2](/packages/wnx-laravel-backup-restore)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
