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

laravelcloud logo
Laravel Cloud

Easily create and manage your servers and deploy your Laravel applications in seconds.

Visit Laravel Cloud

The latest

View all →
Laravel Auditor Audits Your App With Your Own AI Agent image

Laravel Auditor Audits Your App With Your Own AI Agent

Read article
A simple form builder that stays out of your way image

A simple form builder that stays out of your way

Read article
Laravel AI: Trace Agent Runs With Lifecycle Events image

Laravel AI: Trace Agent Runs With Lifecycle Events

Read article
Laravel AI: Get Raw HTTP Responses and Rate Limits image

Laravel AI: Get Raw HTTP Responses and Rate Limits

Read article
Agent Run Observability in Laravel AI SDK 0.11 image

Agent Run Observability in Laravel AI SDK 0.11

Read article
Debounced Queued Event Listeners in Laravel image

Debounced Queued Event Listeners in Laravel

Read article