Laravel扩展推荐:获取模型信息工具“laravel-model-info”

2022-12-27,

Laravel 模型信息 是 Spatie 的一个包,用于获取有关 Laravel 中所有模型的信息项目。如果你正在构建需要以编程方式检查模型的功能,此包会很有帮助。【相关推荐:laravel视频教程】

例如,你可以访问许多重要的详细信息,如数据库表名、属性、关系等:

use Spatie\ModelInfo\ModelInfo;

$model = ModelInfo::for(Post::class);
$model->attributes;
$model->relations;
// etc.

// 属性和关系是集合
$model->attributes->first()->name; // title
$model->attributes->first()->type; // string(255)
$model->attributes->first()->phpType; // string

我在这个包中注意到的一个很棒的功能是获取项目中的所有模型:

// 返回所有应用模型的集合
$models = ModelFinder::all();

要了解更多信息,请查看 Freek Van der Herten 的文 Getting information about all the models in your Laravel app。 你可以在 spatie/laravel-model-info的 GitHub 上获取文档和源代码。

原文地址:https://laravel-news.com/laravel-model-info

译文地址:https://learnku.com/laravel/t/71822

更多编程相关知识,请访问:编程视频!!

以上就是Laravel扩展推荐:获取模型信息工具“laravel-model-info”的详细内容,更多请关注北冥有鱼其它相关文章!

本文转载自【PHP中文网】,希望能给您带来帮助,苟日新、日日新、又日新,生命不息,学习不止。

《Laravel扩展推荐:获取模型信息工具“laravel-model-info”.doc》

下载本文的Word格式文档,以方便收藏与打印。