Commit fdb55ef9 authored by 王源's avatar 王源 🎧

优化mm生成命令代码

parent 800a0248
This diff is collapsed.
...@@ -21,6 +21,7 @@ use Meibuyu\Micro\Annotation\Perm; ...@@ -21,6 +21,7 @@ use Meibuyu\Micro\Annotation\Perm;
*/ */
class %ModelClass%Controller extends AbstractController class %ModelClass%Controller extends AbstractController
{ {
/** /**
* @Inject() * @Inject()
* @var %ModelClass%Repository * @var %ModelClass%Repository
......
...@@ -7,20 +7,21 @@ ...@@ -7,20 +7,21 @@
* Description: * Description:
*/ */
use Hyperf\Database\Schema\Schema;
use Hyperf\Database\Schema\Blueprint;
use Hyperf\Database\Migrations\Migration; use Hyperf\Database\Migrations\Migration;
use Hyperf\Database\Schema\Blueprint;
use Hyperf\Database\Schema\Schema;
use Hyperf\DbConnection\Db; use Hyperf\DbConnection\Db;
class %ClassName% extends Migration class %ClassName% extends Migration
{ {
/** /**
* Run the migrations. * Run the migrations.
*/ */
public function up(): void public function up(): void
{ {
Schema::disableForeignKeyConstraints(); Schema::disableForeignKeyConstraints();
Schema::create('%tablename%', function (Blueprint $table) { Schema::create('%tableName%', function (Blueprint $table) {
%attributes% %attributes%
}); });
%tableComment% %tableComment%
...@@ -33,7 +34,8 @@ class %ClassName% extends Migration ...@@ -33,7 +34,8 @@ class %ClassName% extends Migration
public function down(): void public function down(): void
{ {
Schema::disableForeignKeyConstraints(); Schema::disableForeignKeyConstraints();
Schema::dropIfExists('%tablename%'); Schema::dropIfExists('%tableName%');
Schema::enableForeignKeyConstraints(); Schema::enableForeignKeyConstraints();
} }
} }
...@@ -25,19 +25,11 @@ use Meibuyu\Micro\Repository\Eloquent\BaseRepository; ...@@ -25,19 +25,11 @@ use Meibuyu\Micro\Repository\Eloquent\BaseRepository;
class %ModelClass%RepositoryEloquent extends BaseRepository implements %ModelClass%Repository class %ModelClass%RepositoryEloquent extends BaseRepository implements %ModelClass%Repository
{ {
/**
* %ModelClass% 模型
* @return mixed
*/
public function model() public function model()
{ {
return %ModelClass%::class; return %ModelClass%::class;
} }
/**
* 数据校验器
* @return mixed
*/
public function validator() public function validator()
{ {
return %ModelClass%Validator::class; return %ModelClass%Validator::class;
...@@ -47,7 +39,7 @@ class %ModelClass%RepositoryEloquent extends BaseRepository implements %ModelCla ...@@ -47,7 +39,7 @@ class %ModelClass%RepositoryEloquent extends BaseRepository implements %ModelCla
* 获取数据列表 * 获取数据列表
* @return array * @return array
*/ */
public function list(): array public function list()
{ {
$pageSize = (int)$this->request->input('page_size', DEFAULT_PAGE_SIZE); $pageSize = (int)$this->request->input('page_size', DEFAULT_PAGE_SIZE);
%list% %list%
...@@ -58,7 +50,7 @@ class %ModelClass%RepositoryEloquent extends BaseRepository implements %ModelCla ...@@ -58,7 +50,7 @@ class %ModelClass%RepositoryEloquent extends BaseRepository implements %ModelCla
* @param $id * @param $id
* @return array * @return array
*/ */
public function show($id): array public function show($id)
{ {
%show% %show%
} }
...@@ -68,7 +60,7 @@ class %ModelClass%RepositoryEloquent extends BaseRepository implements %ModelCla ...@@ -68,7 +60,7 @@ class %ModelClass%RepositoryEloquent extends BaseRepository implements %ModelCla
* @param array $attributes * @param array $attributes
* @return bool * @return bool
*/ */
public function create(array $attributes): bool public function create(array $attributes)
{ {
Db::transaction(function () use ($attributes) { Db::transaction(function () use ($attributes) {
%create% %create%
...@@ -82,7 +74,7 @@ class %ModelClass%RepositoryEloquent extends BaseRepository implements %ModelCla ...@@ -82,7 +74,7 @@ class %ModelClass%RepositoryEloquent extends BaseRepository implements %ModelCla
* @param $id * @param $id
* @return bool * @return bool
*/ */
public function update(array $attributes, $id): bool public function update(array $attributes, $id)
{ {
Db::transaction(function () use ($attributes, $id) { Db::transaction(function () use ($attributes, $id) {
%update% %update%
...@@ -96,10 +88,9 @@ class %ModelClass%RepositoryEloquent extends BaseRepository implements %ModelCla ...@@ -96,10 +88,9 @@ class %ModelClass%RepositoryEloquent extends BaseRepository implements %ModelCla
* @return bool * @return bool
* @throws HttpResponseException * @throws HttpResponseException
*/ */
public function delete($id): bool public function delete($id)
{ {
//已用外键做级联删除 和 删除验证,不需要做逻辑验证 return parent::delete($id); // TODO: Change the autogenerated stub
return $this->find($id)->delete();
} }
%rs% %rs%
} }
...@@ -16,6 +16,7 @@ use Meibuyu\Micro\Validator\HyperfValidator; ...@@ -16,6 +16,7 @@ use Meibuyu\Micro\Validator\HyperfValidator;
class %ModelClass%Validator extends HyperfValidator class %ModelClass%Validator extends HyperfValidator
{ {
protected $rules = [ protected $rules = [
ValidatorInterface::RULE_CREATE => [ ValidatorInterface::RULE_CREATE => [
%createRules% %createRules%
...@@ -29,8 +30,4 @@ class %ModelClass%Validator extends HyperfValidator ...@@ -29,8 +30,4 @@ class %ModelClass%Validator extends HyperfValidator
%attributes% %attributes%
]; ];
protected $messages = [
%messages%
];
} }
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