在 Laravel 中从数据库创建模型 [英] Create Models from database in Laravel
问题描述
有没有办法在 Laravel 中从数据库中生成模型?
Is there some way to generate models from database in Laravel?
generators 包只创建一个空模型.
The generators package only create an empty model.
推荐答案
有一个库 Eloquent Model Generator 其目的是使用数据库表作为源创建 Eloquent 模型类.它不仅生成类存根,还生成关系方法、魔术字段的文档块、附加属性等.
There is a library Eloquent Model Generator which aim is creating Eloquent models classes using database tables as a source. It generates not only class stub, but relation methods, docblocks for magic fields, additional properties etc.
它提供了一个控制台命令 php artisan krlove:generate:model ClassName
用于每次调用生成一个类,但您可以创建自己的命令来为数据库中的每个表调用此命令.
It provides a console command php artisan krlove:generate:model ClassName
for generating one class per one call, but you can create your own command to call this command for each table from your database.
这篇关于在 Laravel 中从数据库创建模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!