laravel自动生成model

laravel自动生成model

 

laravel自动生成model

  • 添加PHP扩展
composer require krlove/eloquent-model-generator --dev
  • config/app注册GeneratorServiceProvider类
'providers' => [
    // ...
    Krlove\EloquentModelGenerator\Provider\GeneratorServiceProvider::class,
];
  • 开始生成
//以yd_order_from 表为例
CREATE TABLE `yd_order_from` (
  `id` int(50) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键',
  `order_from_id` int(50) NOT NULL COMMENT '店铺在海淘内的店铺id',
  `idcard_app_key` varchar(100) NOT NULL DEFAULT '' COMMENT '身份证app_key',
  `idcard_secret_key` varchar(100) NOT NULL DEFAULT '' COMMENT '身份证secret_key',
  `idcard_access_token` varchar(100) NOT NULL DEFAULT '' COMMENT '身份证access_token',
  `shop_name` varchar(50) NOT NULL DEFAULT '' COMMENT '店铺名称',
  `create_time` datetime NOT NULL DEFAULT '1970-01-01 00:00:00' COMMENT '创建时间',
  `update_time` datetime NOT NULL DEFAULT '1970-01-01 00:00:00' COMMENT '更新时间',
  `is_activity` tinyint(3) NOT NULL DEFAULT '0' COMMENT '是否可用 0:不可用  1:可用',
  `app_key` varchar(100) NOT NULL DEFAULT '' COMMENT '接口app key',
  `secret_key` varchar(100) NOT NULL DEFAULT '' COMMENT 'API secret',
  `access_token` varchar(100) NOT NULL DEFAULT '' COMMENT 'API access',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT COMMENT='店铺信息表';

//命令
 php artisan krlove:generate:model OrderFrom --table-name=yd_order_from --output-path=./Model --namespace=App\\Model

//生成后

  • https://github.com/krlove/eloquent-model-generator
 
 
 
 
 
 
 
posted @ 2019-01-05 17:31 节奏型男-全栈 阅读(...) 评论(...) 编辑 收藏

你可能感兴趣的:(php)