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

优化mm生成命令代码

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