码迷,mamicode.com
首页 > 其他好文 > 详细

laravel自动生成model

时间:2019-01-05 19:43:57      阅读:310      评论:0      收藏:0      [点我收藏+]

标签:接口   身份证   default   orm   namespace   min   prope   arc   null   

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

//生成后

<?php

namespace App\Model;

use Illuminate\Database\Eloquent\Model;

/**
 * @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‘];

}
  • https://github.com/krlove/eloquent-model-generator

laravel自动生成model

标签:接口   身份证   default   orm   namespace   min   prope   arc   null   

原文地址:https://www.cnblogs.com/frankltf/p/10225375.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!