• laravel自动生成model


    laravel自动生成model

    • 添加PHP扩展
    composer require krlove/eloquent-model-generator --dev
    
    • config/app注册GeneratorServiceProvider类
    'providers' => [
        // ...
        KrloveEloquentModelGeneratorProviderGeneratorServiceProvider::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
    
    //生成后
    
    <?php
    
    namespace AppModel;
    
    use IlluminateDatabaseEloquentModel;
    
    /**
     * @property int $id
     * @property int $order_from_id
     * @property string $idcard_app_key
     * @property string $idcard_secret_key
     * @property string $idcard_access_token
     * @property string $shop_name
     * @property string $create_time
     * @property string $update_time
     * @property boolean $is_activity
     * @property string $app_key
     * @property string $secret_key
     * @property string $access_token
     */
    class OrderFrom extends Model
    {
        /**
         * The table associated with the model.
         * 
         * @var string
         */
        protected $table = 'yd_order_from';
    
        /**
         * @var array
         */
        protected $fillable = ['order_from_id', 'idcard_app_key', 'idcard_secret_key', 'idcard_access_token', 'shop_name', 'create_time', 'update_time', 'is_activity', 'app_key', 'secret_key', 'access_token'];
    
    }
    
  • 相关阅读:
    Maven插件
    Maven 构建生命周期
    Maven POM
    JMeter录制登录测试
    IntelliJ IDEA官方下载地址
    Eplise快捷键
    Eclipse-maven相关配置
    vs2019添加引用出错:对COM组件的调用返回了错误HRESULT E_FAIL
    Java学习--多线程(1)
    SQL Server查询重复数据
  • 原文地址:https://www.cnblogs.com/frankltf/p/10225375.html
Copyright © 2020-2023  润新知