From d4ec2d104f15c555bc7bcc88b8e04c931fd653b2 Mon Sep 17 00:00:00 2001 From: JaguarJack Date: Sat, 26 Dec 2020 20:56:10 +0800 Subject: [PATCH] =?UTF-8?q?fixed:=E4=BF=AE=E6=94=B9=E5=91=BD=E4=BB=A4?= =?UTF-8?q?=E8=A1=8C=E6=97=A0=E6=B3=95=E7=94=9F=E6=88=90model=20field?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- extend/catcher/Utils.php | 15 ++++++++++++++- extend/catcher/generate/factory/Model.php | 3 +-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/extend/catcher/Utils.php b/extend/catcher/Utils.php index 1aa8cf2..d92d673 100644 --- a/extend/catcher/Utils.php +++ b/extend/catcher/Utils.php @@ -152,7 +152,7 @@ class Utils } /** - * 删除前缀 + * 删除表前缀 * * @time 2020年12月01日 * @param string $table @@ -163,6 +163,19 @@ class Utils return str_replace(self::tablePrefix(), '', $table); } + /** + * 添加表前缀 + * + * @time 2020年12月26日 + * @param string $table + * @return string + */ + public static function tableWithPrefix(string $table) + { + return Str::contains($table, self::tablePrefix()) ? + $table : self::tablePrefix() . $table; + } + /** * 是否是超级管理员 * diff --git a/extend/catcher/generate/factory/Model.php b/extend/catcher/generate/factory/Model.php index c750f77..9223016 100644 --- a/extend/catcher/generate/factory/Model.php +++ b/extend/catcher/generate/factory/Model.php @@ -50,7 +50,7 @@ class Model extends Factory { $extra = $params['extra']; - $table = $params['table']; + $table = Utils::tableWithPrefix($params['table']); [$modelName, $namespace] = $this->parseFilename($params['model']); @@ -92,7 +92,6 @@ class Model extends Factory (new Arr)->build(Db::getFields($table)) )->docComment('// 数据库字段映射')); }); - })->getContent(); } } \ No newline at end of file