diff --git a/extend/catcher/Utils.php b/extend/catcher/Utils.php index 88dc22a..1aa8cf2 100644 --- a/extend/catcher/Utils.php +++ b/extend/catcher/Utils.php @@ -151,6 +151,18 @@ class Utils return \config('database.connections.mysql.prefix'); } + /** + * 删除前缀 + * + * @time 2020年12月01日 + * @param string $table + * @return string|string[] + */ + public static function tableWithoutPrefix(string $table) + { + return str_replace(self::tablePrefix(), '', $table); + } + /** * 是否是超级管理员 * diff --git a/extend/catcher/generate/factory/Model.php b/extend/catcher/generate/factory/Model.php index 4f614aa..c375b4d 100644 --- a/extend/catcher/generate/factory/Model.php +++ b/extend/catcher/generate/factory/Model.php @@ -11,6 +11,7 @@ use catcher\generate\build\classes\Uses; use catcher\generate\build\types\Arr; use catcher\traits\db\BaseOptionsTrait; use catcher\traits\db\ScopeTrait; +use catcher\Utils; use think\facade\Db; use think\helper\Str; @@ -80,7 +81,9 @@ class Model extends Factory } $class->addProperty( - (new Property('name'))->default($table)->docComment('// 表名') + (new Property('name'))->default( + Utils::tableWithoutPrefix($table) + )->docComment('// 表名') ); $class->when($this->hasTableExists($table), function ($class) use ($table){