Skip to content

如何定制 gen:model 命令 #2982

Answered by limingxinleo
limingxinleo asked this question in Q&A
Discussion options

You must be logged in to vote

其实我们可以通过重写 ModelUpdateVisitor,很简单的处理这件事。

创建模型

我们先在原来的情况下,执行 gen:model,为了后面高度定制,我们先将 $timestamps 设置为 false,这样 created_atupdated_at 默认都会转化为 string

以下为生成的模型:

<?php

declare(strict_types=1);
/**
 * This file is part of Hyperf.
 *
 * @link     https://www.hyperf.io
 * @document https://hyperf.wiki
 * @contact  [email protected]
 * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
 */
namespace App\Model;

/**
 * @property int $id
 * @property int $count
 * @property float $float_num
 * @property string $str
 * @property string $json
 * @property string $created_at
 * @property string $updated_at
 */
class UserExt extends Model
{
    public $timestamps = false;

    /**
     * Th…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@limingxinleo
Comment options

limingxinleo Dec 16, 2020
Maintainer Author

Answer selected by limingxinleo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant