Loading src/Command/MakeModelCommand.php +7 −12 Original line number Diff line number Diff line Loading @@ -454,8 +454,7 @@ class MakeModelCommand extends HyperfCommand /** * 创建验证文件 */ private function makeValidator() private function makeValidator() { $stubFile = $this->path . 'validator.stub'; $folder = $this->appPath . '/Validators'; Loading Loading @@ -570,8 +569,7 @@ class MakeModelCommand extends HyperfCommand $this->writeToFile($file, $content); } private function makeRepositoryInterface() private function makeRepositoryInterface() { $stubFile = $this->path . 'repositoryInterface.stub'; $folder = $this->appPath . '/Repository/Interfaces'; Loading Loading @@ -600,7 +598,7 @@ class MakeModelCommand extends HyperfCommand $content = file_get_contents($stubFile); $info = $this->currentTableStructure; //列表 $list = "\$conditions = \$this->request->input();\n"; $list = "\$conditions = \$this->request->inputs();\n"; $list .= "\t\t\$list = \$this->model->where(function (\$q) use (\$conditions) {\n"; foreach ($info['fields'] as $v) { if (Str::endsWith($v['column_name'], "_id")) { Loading Loading @@ -669,7 +667,7 @@ class MakeModelCommand extends HyperfCommand foreach ($info['relations']['hasMany'] as $v) { $rs .= "\n\tpublic function {$v['function']}(\$id): array\n"; $rs .= "\t{\n"; $rs .= "\t\t\$pageSize = (int)\$this->request->input('page_size', env(\"DEFAULT_PAGE_SIZE\",10));\n"; $rs .= "\t\t\$pageSize = (int)\$this->request->input('page_size', DEFAULT_PAGE_SIZE);\n"; $rs .= "\t\treturn \$this->find(\$id)->{$v['function']}()->orderByDesc('id')->paginate(\$pageSize)->toArray();\n"; $rs .= "\t}\n"; } Loading Loading @@ -1017,14 +1015,12 @@ class MakeModelCommand extends HyperfCommand /**生成迁移文件的日期格式 * @return string */ private function getDatePrefix(): string private function getDatePrefix(): string { return date('Y_m_dHis'); } public function configure() public function configure() { //$this->call() parent::configure(); Loading @@ -1042,8 +1038,7 @@ class MakeModelCommand extends HyperfCommand * 配置文件内容 * @return array */ protected function getArguments() protected function getArguments() { return [ ['name', InputArgument::OPTIONAL, '数据库表名'], Loading src/Command/stubs/controller.stub +3 −1 Original line number Diff line number Diff line Loading @@ -40,7 +40,7 @@ class %ModelClass%Controller extends AbstractController /** * 获取列表数据 * @Perm("index") * @param $id id编号 * @param int $id id编号 * @return mixed */ public function show($id) Loading @@ -61,6 +61,7 @@ class %ModelClass%Controller extends AbstractController /** * 更新数据 * @param int $id id编号 * @return mixed */ public function update($id) Loading @@ -71,6 +72,7 @@ class %ModelClass%Controller extends AbstractController /** * 删除单条数据 * @param int $id id编号 * @return mixed */ public function delete($id) Loading src/Command/stubs/model.stub +1 −1 Original line number Diff line number Diff line Loading @@ -13,7 +13,7 @@ namespace App\Model; %namespace% /** * 模型类 %ClassName% * @package App\Models * @package App\Model %properties% */ class %ClassName% extends Model Loading src/Command/stubs/repository.stub +7 −8 Original line number Diff line number Diff line Loading @@ -18,16 +18,15 @@ use Meibuyu\Micro\Exceptions\HttpResponseException; use Meibuyu\Micro\Repository\Eloquent\BaseRepository; /** * %ModelClass%RepositoryEloquent 类. * * @package namespace App\Repository\Eloquent; * Class %ModelClass%RepositoryEloquent * @package App\Repository\Eloquent; */ class %ModelClass%RepositoryEloquent extends BaseRepository implements %ModelClass%Repository { /** * %ModelClass% 模型 * @return %ModelClass% * @return %ModelClass%|string */ public function model(): %ModelClass% { Loading @@ -36,7 +35,7 @@ class %ModelClass%RepositoryEloquent extends BaseRepository implements %ModelCla /** * 数据校验器 * @return %ModelClass%Validator * @return %ModelClass%Validator|string */ public function validator(): %ModelClass%Validator { Loading @@ -49,8 +48,8 @@ class %ModelClass%RepositoryEloquent extends BaseRepository implements %ModelCla */ public function list(): array { $pageSize = (int)$this->request->input('page_size', env("DEFAULT_PAGE_SIZE",10)); %list%; $pageSize = (int)$this->request->input('page_size', DEFAULT_PAGE_SIZE); %list% } /** Loading @@ -60,7 +59,7 @@ class %ModelClass%RepositoryEloquent extends BaseRepository implements %ModelCla */ public function show($id): array { %show%; %show% } /** Loading src/Command/stubs/repositoryInterface.stub +2 −3 Original line number Diff line number Diff line Loading @@ -14,9 +14,8 @@ namespace App\Repository\Interfaces; use Meibuyu\Micro\Repository\Contracts\RepositoryInterface; /** * %ClassName% 接口类. * * @package namespace App\Repository\Interfaces; * Interface %ClassName% * @package App\Repository\Interfaces */ interface %ClassName% extends RepositoryInterface { Loading Loading
src/Command/MakeModelCommand.php +7 −12 Original line number Diff line number Diff line Loading @@ -454,8 +454,7 @@ class MakeModelCommand extends HyperfCommand /** * 创建验证文件 */ private function makeValidator() private function makeValidator() { $stubFile = $this->path . 'validator.stub'; $folder = $this->appPath . '/Validators'; Loading Loading @@ -570,8 +569,7 @@ class MakeModelCommand extends HyperfCommand $this->writeToFile($file, $content); } private function makeRepositoryInterface() private function makeRepositoryInterface() { $stubFile = $this->path . 'repositoryInterface.stub'; $folder = $this->appPath . '/Repository/Interfaces'; Loading Loading @@ -600,7 +598,7 @@ class MakeModelCommand extends HyperfCommand $content = file_get_contents($stubFile); $info = $this->currentTableStructure; //列表 $list = "\$conditions = \$this->request->input();\n"; $list = "\$conditions = \$this->request->inputs();\n"; $list .= "\t\t\$list = \$this->model->where(function (\$q) use (\$conditions) {\n"; foreach ($info['fields'] as $v) { if (Str::endsWith($v['column_name'], "_id")) { Loading Loading @@ -669,7 +667,7 @@ class MakeModelCommand extends HyperfCommand foreach ($info['relations']['hasMany'] as $v) { $rs .= "\n\tpublic function {$v['function']}(\$id): array\n"; $rs .= "\t{\n"; $rs .= "\t\t\$pageSize = (int)\$this->request->input('page_size', env(\"DEFAULT_PAGE_SIZE\",10));\n"; $rs .= "\t\t\$pageSize = (int)\$this->request->input('page_size', DEFAULT_PAGE_SIZE);\n"; $rs .= "\t\treturn \$this->find(\$id)->{$v['function']}()->orderByDesc('id')->paginate(\$pageSize)->toArray();\n"; $rs .= "\t}\n"; } Loading Loading @@ -1017,14 +1015,12 @@ class MakeModelCommand extends HyperfCommand /**生成迁移文件的日期格式 * @return string */ private function getDatePrefix(): string private function getDatePrefix(): string { return date('Y_m_dHis'); } public function configure() public function configure() { //$this->call() parent::configure(); Loading @@ -1042,8 +1038,7 @@ class MakeModelCommand extends HyperfCommand * 配置文件内容 * @return array */ protected function getArguments() protected function getArguments() { return [ ['name', InputArgument::OPTIONAL, '数据库表名'], Loading
src/Command/stubs/controller.stub +3 −1 Original line number Diff line number Diff line Loading @@ -40,7 +40,7 @@ class %ModelClass%Controller extends AbstractController /** * 获取列表数据 * @Perm("index") * @param $id id编号 * @param int $id id编号 * @return mixed */ public function show($id) Loading @@ -61,6 +61,7 @@ class %ModelClass%Controller extends AbstractController /** * 更新数据 * @param int $id id编号 * @return mixed */ public function update($id) Loading @@ -71,6 +72,7 @@ class %ModelClass%Controller extends AbstractController /** * 删除单条数据 * @param int $id id编号 * @return mixed */ public function delete($id) Loading
src/Command/stubs/model.stub +1 −1 Original line number Diff line number Diff line Loading @@ -13,7 +13,7 @@ namespace App\Model; %namespace% /** * 模型类 %ClassName% * @package App\Models * @package App\Model %properties% */ class %ClassName% extends Model Loading
src/Command/stubs/repository.stub +7 −8 Original line number Diff line number Diff line Loading @@ -18,16 +18,15 @@ use Meibuyu\Micro\Exceptions\HttpResponseException; use Meibuyu\Micro\Repository\Eloquent\BaseRepository; /** * %ModelClass%RepositoryEloquent 类. * * @package namespace App\Repository\Eloquent; * Class %ModelClass%RepositoryEloquent * @package App\Repository\Eloquent; */ class %ModelClass%RepositoryEloquent extends BaseRepository implements %ModelClass%Repository { /** * %ModelClass% 模型 * @return %ModelClass% * @return %ModelClass%|string */ public function model(): %ModelClass% { Loading @@ -36,7 +35,7 @@ class %ModelClass%RepositoryEloquent extends BaseRepository implements %ModelCla /** * 数据校验器 * @return %ModelClass%Validator * @return %ModelClass%Validator|string */ public function validator(): %ModelClass%Validator { Loading @@ -49,8 +48,8 @@ class %ModelClass%RepositoryEloquent extends BaseRepository implements %ModelCla */ public function list(): array { $pageSize = (int)$this->request->input('page_size', env("DEFAULT_PAGE_SIZE",10)); %list%; $pageSize = (int)$this->request->input('page_size', DEFAULT_PAGE_SIZE); %list% } /** Loading @@ -60,7 +59,7 @@ class %ModelClass%RepositoryEloquent extends BaseRepository implements %ModelCla */ public function show($id): array { %show%; %show% } /** Loading
src/Command/stubs/repositoryInterface.stub +2 −3 Original line number Diff line number Diff line Loading @@ -14,9 +14,8 @@ namespace App\Repository\Interfaces; use Meibuyu\Micro\Repository\Contracts\RepositoryInterface; /** * %ClassName% 接口类. * * @package namespace App\Repository\Interfaces; * Interface %ClassName% * @package App\Repository\Interfaces */ interface %ClassName% extends RepositoryInterface { Loading