Get Helpful Information about Models in Laravel
Published on by Paul Redmond
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.