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

来源:php中文网 | 2022-12-26 20:03:46 |


【资料图】

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 上获取文档和源代码。

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

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

关键词: Laravel