Laravel Packages

Eloquent Inspector for Laravel

Published
Eloquent Inspector for Laravel image

Laravel Eloquent Inspector is a package by Andrea Marco Sartori to inspect models and collect properties, relationships, and more.

This package provides helpful information about the use statements of a model, model properties, and model relationships:

 
// All `use` statements for a model
$useStatements = Inspector::inspect(User::class)->getUseStatements();
/*
[
'Model' => 'Illuminate\Database\Eloquent\Model',
'Baz' => 'Foo\Bar',
]
*/
 
 
// Model properties
$properties = Inspector::inspect(User::class)->getProperties();
 
$properties['id']->name; // id
$properties['id']->type; // int
$properties['id']->dbType; // integer
$properties['id']->nullable; // false
$properties['id']->default; // null
 
 
$relationships = Inspector::inspect(User::class)->getRelationships();
 
$relationships['posts']->name; // posts
$relationships['posts']->type; // hasMany
// Illuminate\Database\Eloquent\Relations\HasMany
$relationships['posts']->class;
$relationships['posts']->model; // App\Models\Post
$relationships['posts']->relatesToMany; // true

Model relationships and properties return an array, with the key being the property/relationship name and the value being an object with detailed information about that property/relationship.

You can learn more about this package, get full installation instructions, and view the source code on GitHub.

Paul Redmond photo

Staff writer at Laravel News. Full stack web developer and author.

Sponsored

masteringlaravel logo
Laravel Code Review

Get expert guidance in a few days with a Laravel code review

Visit Laravel Code Review

The latest

View all →
CPX: The Composer Package Executor for PHP image

CPX: The Composer Package Executor for PHP

Read article
Laravel AI SDK Adds Human-in-the-Loop Tool Approval image

Laravel AI SDK Adds Human-in-the-Loop Tool Approval

Read article
Pest 5 Released With Test Impact Analysis, Agent Verification, and Evals image

Pest 5 Released With Test Impact Analysis, Agent Verification, and Evals

Read article
Queue-SQL: Run Mass Deletes and Updates Across Parallel Queue Jobs image

Queue-SQL: Run Mass Deletes and Updates Across Parallel Queue Jobs

Read article
Blade Formatting in Laravel Pint image

Blade Formatting in Laravel Pint

Read article
Inertia DevTools Is Now on the Chrome Web Store image

Inertia DevTools Is Now on the Chrome Web Store

Read article