New

Just launched: Vueblocks, a brand-new search engine for Vue packages! Explore Vueblocks →

cerbero/eloquent-inspector

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

Larablocks Analysis

cerbero/eloquent-inspector works with Laravel 8 (latest release 1.0.0, Jan 18, 2022), which reached end of life on Jan 24, 2023: no more fixes, even for security.

Recommendation checks

Not advised

Not advised: no release or commit in over 2 years.

  • No release or commit in over 2 years
  • Supports only Laravel 8, past end of life since Jan 24, 2023
  • No release in the last 12 months (last: Jan 18, 2022)
  • 2,433 downloads a month (needs 10,000)
  • 112 GitHub stars (at least 100)

State

Likely abandoned
  • No release or commit in over 2 years.
  • Last stable release: Jan 18, 2022.
  • No releases in the last 12 months.
  • First released: Jan 18, 2022.
  • Monthly downloads: 2,433, about the same as six months ago.
  • 0 open issues on GitHub.

Data from Packagist and GitHub, checked by Larablocks on Dec 1, 2026.

Install
composer require cerbero/eloquent-inspector
Latest Version:1.0.0
PHP:^8.0
Laravel:8
License:MIT
Last Updated:Jan 18, 2022
Links: GitHub  ·  Packagist
Maintainer: cerbero

🕵️ Eloquent Inspector

Author PHP Version Laravel Version Octane Compatibility Build Status Coverage Status Quality Score Latest Version Software License PSR-12 Total Downloads

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

Install

Via Composer

composer require cerbero/eloquent-inspector

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' => <Cerbero\EloquentInspector\Dtos\Property>,
    'name' => <Cerbero\EloquentInspector\Dtos\Property>,
    ...
]
*/

$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' => <Cerbero\EloquentInspector\Dtos\Relationship>,
    'tags' => <Cerbero\EloquentInspector\Dtos\Relationship>,
    ...
]
*/

$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

Please see CHANGELOG for more information on what has changed recently.

Testing

composer test

Contributing

Please see CONTRIBUTING and CODE_OF_CONDUCT for details.

Security

If you discover any security related issues, please email andrea.marco.sartori@gmail.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

Related Packages

jenssegers/model

An Laravel eloquent-like model class, for Laravel and other frameworks

4,816,176 393
czim/laravel-nestedupdater

Eloquent model updater for nested relations data for Laravel.

54,483 19
custom-d/eloquent-model-encrypt

A eloquent model encrypt

6,242
czim/laravel-modelcomparer

Performs a deep-nested comparison of a model's before/after state.

4,738 2
joemugen/eloquenty-model

A Laravel eloquent-like model class, for Laravel and other frameworks

3,751 0

Version History

Version Released PHP Laravel License
1.0.0 ^8.0 >=8.0 MIT