• Reading time ~ 1 min
  • 19.09.2022

Laravel Model Info is a package by Spatie to get information on all the models in your Laravel project. This package is helpful if you're building functionality where you need to programmatically inspect models.

For example, you can access many important details like the database table name, attributes, relationships, and more:

use Spatie\ModelInfo\ModelInfo;
 
$model = ModelInfo::for(Post::class);
$model->attributes;
$model->relations;
// etc.
 
// Attributes and relations are collections
$model->attributes->first()->name; // title
$model->attributes->first()->type; // string(255)
$model->attributes->first()->phpType; // string

One of the fantastic features I noticed in this package is getting all the models in your project:

// Returns a collection of all your app's models
$models = ModelFinder::all();

To learn more, check out Freek Van der Herten's article Getting information about all the models in your Laravel app. You can get documentation and the source code on GitHub at spatie/laravel-model-info.

Comments

No comments yet
Yurij Finiv

Yurij Finiv

Full stack

ABOUT

Professional Fullstack Developer with extensive experience in website and desktop application development. Proficient in a wide range of tools and technologies, including Bootstrap, Tailwind, HTML5, CSS3, PUG, JavaScript, Alpine.js, jQuery, PHP, MODX, and Node.js. Skilled in website development using Symfony, MODX, and Laravel. Experience: Contributed to the development and translation of MODX3 i...

About author CrazyBoy49z
WORK EXPERIENCE
Contact
Ukraine, Lutsk
+380979856297