Commit 84d84ec6 authored by 王源's avatar 王源 🎧

优化生成模板

parent 6e7419a2
......@@ -454,8 +454,7 @@ class MakeModelCommand extends HyperfCommand
/**
* 创建验证文件
*/
private
function makeValidator()
private function makeValidator()
{
$stubFile = $this->path . 'validator.stub';
$folder = $this->appPath . '/Validators';
......@@ -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';
......@@ -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")) {
......@@ -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";
}
......@@ -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();
......@@ -1042,8 +1038,7 @@ class MakeModelCommand extends HyperfCommand
* 配置文件内容
* @return array
*/
protected
function getArguments()
protected function getArguments()
{
return [
['name', InputArgument::OPTIONAL, '数据库表名'],
......
......@@ -40,7 +40,7 @@ class %ModelClass%Controller extends AbstractController
/**
* 获取列表数据
* @Perm("index")
* @param $id id编号
* @param int $id id编号
* @return mixed
*/
public function show($id)
......@@ -61,6 +61,7 @@ class %ModelClass%Controller extends AbstractController
/**
* 更新数据
* @param int $id id编号
* @return mixed
*/
public function update($id)
......@@ -71,6 +72,7 @@ class %ModelClass%Controller extends AbstractController
/**
* 删除单条数据
* @param int $id id编号
* @return mixed
*/
public function delete($id)
......
......@@ -13,7 +13,7 @@ namespace App\Model;
%namespace%
/**
* 模型类 %ClassName%
* @package App\Models
* @package App\Model
%properties%
*/
class %ClassName% extends Model
......
......@@ -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%
{
......@@ -36,7 +35,7 @@ class %ModelClass%RepositoryEloquent extends BaseRepository implements %ModelCla
/**
* 数据校验器
* @return %ModelClass%Validator
* @return %ModelClass%Validator|string
*/
public function validator(): %ModelClass%Validator
{
......@@ -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%
}
/**
......@@ -60,7 +59,7 @@ class %ModelClass%RepositoryEloquent extends BaseRepository implements %ModelCla
*/
public function show($id): array
{
%show%;
%show%
}
/**
......
......@@ -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
{
......
......@@ -9,7 +9,6 @@
declare(strict_types=1);
namespace App\Validators;
use Meibuyu\Micro\Validator\Contracts\ValidatorInterface;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment