PHPackages                             cerbero/eloquent-inspector - 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. cerbero/eloquent-inspector

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

cerbero/eloquent-inspector
==========================

Inspect Laravel Eloquent models to collect properties, relationships and more.

1.0.0(4y ago)11229.2k↑37.9%2MITPHPPHP ^8.0

Since Jan 18Pushed 4y ago1 watchersCompare

[ Source](https://github.com/cerbero90/eloquent-inspector)[ Packagist](https://packagist.org/packages/cerbero/eloquent-inspector)[ Docs](https://github.com/cerbero90/eloquent-inspector)[ GitHub Sponsors](https://github.com/cerbero90)[ RSS](/packages/cerbero-eloquent-inspector/feed)WikiDiscussions develop Synced 1mo ago

READMEChangelogDependencies (6)Versions (3)Used By (0)

🕵️ Eloquent Inspector
=====================

[](#️-eloquent-inspector)

[![Author](https://camo.githubusercontent.com/fffbc89ca2742dccf8be167716e04b7125a913abae0da6a488131999dab8ca25/68747470733a2f2f696d672e736869656c64732e696f2f7374617469632f76313f6c6162656c3d617574686f72266d6573736167653d6365726265726f393026636f6c6f723d353041424631266c6f676f3d74776974746572267374796c653d666c61742d737175617265)](https://twitter.com/cerbero90)[![PHP Version](https://camo.githubusercontent.com/935c5645ba57c64cb3c484359c0e2b81e049d92dffd2d039583dc5240a2eba39/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6365726265726f2f656c6f7175656e742d696e73706563746f723f636f6c6f723d253233344635423933266c6f676f3d706870267374796c653d666c61742d737175617265)](https://www.php.net)[![Laravel Version](https://camo.githubusercontent.com/ea18c12edb72175e59aba015ab13db2e68fb8c79a9b89a328c648ecdef4c42f0/68747470733a2f2f696d672e736869656c64732e696f2f7374617469632f76313f6c6162656c3d6c61726176656c266d6573736167653d254532253839254135382e3026636f6c6f723d666632643230266c6f676f3d6c61726176656c267374796c653d666c61742d737175617265)](https://laravel.com)[![Octane Compatibility](https://camo.githubusercontent.com/2bab41dd2c082d2a58c113b9fdd1fa5e56faafbfabd83b9195bab7ef1484b9e1/68747470733a2f2f696d672e736869656c64732e696f2f7374617469632f76313f6c6162656c3d6f6374616e65266d6573736167653d636f6d70617469626c6526636f6c6f723d666632643230266c6f676f3d6c61726176656c267374796c653d666c61742d737175617265)](https://github.com/laravel/octane)[![Build Status](https://camo.githubusercontent.com/e2accf71bd648ef5d126530b8956f3b0fe0ec8ca68be697309d975377d7e4b92/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f6365726265726f39302f656c6f7175656e742d696e73706563746f722f6275696c643f7374796c653d666c61742d737175617265266c6f676f3d676974687562)](https://github.com/cerbero90/eloquent-inspector/actions?query=workflow%3Abuild)[![Coverage Status](https://camo.githubusercontent.com/51292d42b2359c658a76e73572b24d99f7064a9a329dc3e4a9ebef30f8a996e0/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f6365726265726f39302f656c6f7175656e742d696e73706563746f722e7376673f7374796c653d666c61742d737175617265266c6f676f3d7363727574696e697a6572)](https://scrutinizer-ci.com/g/cerbero90/eloquent-inspector/code-structure)[![Quality Score](https://camo.githubusercontent.com/919fbe560b6dfe354172adace55d0d9b7ee6458cc7e17f4e903bbcf78808e649/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f6365726265726f39302f656c6f7175656e742d696e73706563746f722e7376673f7374796c653d666c61742d737175617265266c6f676f3d7363727574696e697a6572)](https://scrutinizer-ci.com/g/cerbero90/eloquent-inspector)[![Latest Version](https://camo.githubusercontent.com/09ee908cdffa2abe4455b288bf8e32526649d04e70c2dc29bb87cfd5dd952fe4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6365726265726f2f656c6f7175656e742d696e73706563746f722e7376673f6c6162656c3d76657273696f6e267374796c653d666c61742d737175617265)](https://packagist.org/packages/cerbero/eloquent-inspector)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![PSR-12](https://camo.githubusercontent.com/9ba5754b3504e97a10e2b2f84770a218e69e544e9de8943eceb0b67599c83c6c/68747470733a2f2f696d672e736869656c64732e696f2f7374617469632f76313f6c6162656c3d636f6d706c69616e6365266d6573736167653d5053522d313226636f6c6f723d626c7565267374796c653d666c61742d737175617265)](https://www.php-fig.org/psr/psr-12/)[![Total Downloads](https://camo.githubusercontent.com/3c35f2ba952b33fe317d56f4f454896a2b0d3bec3030a35a4067909eeb9f9ecd/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6365726265726f2f656c6f7175656e742d696e73706563746f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/cerbero/eloquent-inspector)

Inspect Laravel Eloquent models to collect properties, relationships and more.

Install
-------

[](#install)

Via Composer

```
composer require cerbero/eloquent-inspector
```

Usage
-----

[](#usage)

To inspect an Eloquent model, we can simply pass its class name to the `inspect()` method:

```
use App\Models\User;
use Cerbero\EloquentInspector\Inspector;

$inspector = Inspector::inspect(User::class);
```

An `Inspector` singleton is created every time a new model is inspected, this lets us inspect the same model multiple times while running the inspection logic only once.

If we need to free memory or cleanup some inspected model information, we can either flush all model inspections, flush only one model inspection or tell an inspection to forget its data:

```
// flush information of all inspected models
Inspector::flush();

// flush information of an inspected model
Inspector::flush(User::class);

// forget information of the current inspection
Inspector::inspect(User::class)->forget();
```

To retrieve the class of the inspected model from an `Inspector`, we can call `getModel()`:

```
$model = Inspector::inspect(User::class)->getModel(); // App\Models\User
```

The method `getUseStatements()` returns an array with all the `use` statements of a model, keyed by either the class name or the alias:

```
use Illuminate\Database\Eloquent\Model;
use Foo\Bar as Baz;

class User extends Model
{
    // ...
}

$useStatements = Inspector::inspect(User::class)->getUseStatements();
/*
[
    'Model' => 'Illuminate\Database\Eloquent\Model',
    'Baz' => 'Foo\Bar',
]
*/
```

Calling `getProperties()` performs a scan of the model database table and returns an array of `Property` instances containing the properties information. The array is keyed by the properties name:

```
$properties = Inspector::inspect(User::class)->getProperties();
/*
[
    'id' => ,
    'name' => ,
    ...
]
*/

$properties['id']->name; // id
$properties['id']->type; // int
$properties['id']->dbType; // integer
$properties['id']->nullable; // false
$properties['id']->default; // null
```

To inspect the relationships of a model, we can call the method `getRelationships()`. The result is an array of `Relationship` instances, keyed by the relationship name, containing all the relationships information:

```
$relationships = Inspector::inspect(User::class)->getRelationships();
/*
[
    'posts' => ,
    'tags' => ,
    ...
]
*/

$relationships['posts']->name; // posts
$relationships['posts']->type; // hasMany
$relationships['posts']->class; // Illuminate\Database\Eloquent\Relations\HasMany
$relationships['posts']->model; // App\Models\Post
$relationships['posts']->relatesToMany; // true
```

Change log
----------

[](#change-log)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Testing
-------

[](#testing)

```
composer test
```

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

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) and [CODE\_OF\_CONDUCT](CODE_OF_CONDUCT.md) for details.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Andrea Marco Sartori](https://twitter.com/cerbero90)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity43

Moderate usage in the ecosystem

Community9

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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

1582d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/596523?v=4)[Matteo Picciolini](/maintainers/cerbero)[@cerbero](https://github.com/cerbero)

---

Top Contributors

[![cerbero90](https://avatars.githubusercontent.com/u/5838106?v=4)](https://github.com/cerbero90 "cerbero90 (8 commits)")

---

Tags

laravelmodeleloquent

###  Code Quality

TestsPest

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/cerbero-eloquent-inspector/health.svg)

```
[![Health](https://phpackages.com/badges/cerbero-eloquent-inspector/health.svg)](https://phpackages.com/packages/cerbero-eloquent-inspector)
```

###  Alternatives

[mongodb/laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel

7.1k7.2M71](/packages/mongodb-laravel-mongodb)[tucker-eric/eloquentfilter

An Eloquent way to filter Eloquent Models

1.8k4.8M26](/packages/tucker-eric-eloquentfilter)[dyrynda/laravel-model-uuid

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

4802.8M8](/packages/dyrynda-laravel-model-uuid)[spiritix/lada-cache

A Redis based, automated and scalable database caching layer for Laravel

591444.8k2](/packages/spiritix-lada-cache)[rennokki/befriended

Eloquent Befriended brings social media-like features like following, blocking and filtering content based on following or blocked models.

76292.2k1](/packages/rennokki-befriended)[pdphilip/elasticsearch

An Elasticsearch implementation of Laravel's Eloquent ORM

145360.2k4](/packages/pdphilip-elasticsearch)

PHPackages © 2026

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