简介:前言在开发会遇到将数据库中的数据转换成驼峰方式命名。实现所有需要转换的model都添加:protected $convertNameToCamel = true;  我一般新创建一个类,然后...

前言

在开发会遇到将数据库中的数据转换成驼峰方式命名。

实现

所有需要转换的model都添加:protected $convertNameToCamel = true;  我一般新创建一个类,然后其他继承更方便。

<?php

declare(strict_types=1);

namespace app\common\model;

use think\Model;
use think\model\concern\SoftDelete;

/**
 * @mixin \think\Model
 */
class BaseModel extends Model
{
    /**
     * 自动驼峰命名
     * @var string
     */
    protected $convertNameToCamel = true;

    /**
     * 自动时间戳类型
     * @var string
     */
    protected $autoWriteTimestamp = true;

    /**
     * 添加时间
     * @var string
     */
    protected $createTime = 'create_time';

    /**
     * 更新时间
     * @var string
     */
    protected $updateTime = 'update_time';

    /**
     * 软删除
     */
    use SoftDelete;
    protected $deleteTime = false;
}