shibuyakosuke / laravel-ddl-export
通过 artisan 命令将表定义导出为电子表格。
v0.3.3
2024-04-24 15:01 UTC
Requires
- php: ^7.4 | ^8.0 | ^8.1 | ^8.2
- laravel/framework: 7.30.4 | ^8.0 | ^9.0 | ^10.0 | ^11.0
- maatwebsite/excel: ^3.1
Requires (Dev)
- phpstan/phpstan: ^0.12.85
README
从 Laravel 项目中,以 xlsx 格式导出表定义!
通过 artisan 命令将表定义导出为电子表格。
适用于 MySQL, PostgreSQL
安装
$ composer require shibuyakosuke/laravel-ddl-export
使用方法
使用注释编写您的迁移文件。要添加表注释,请使用这个库。
<?php use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; class CreateUsersTable extends Migration { /** * Run the migrations. * * @return void */ public function up() { Schema::create('users', function (Blueprint $table) { $table->id()->comment('ID'); $table->string('name')->comment('氏名'); $table->string('email')->unique()->comment('メールアドレス'); $table->timestamp('email_verified_at')->nullable()->comment('メール認証日時'); $table->string('password')->comment('パスワード'); $table->rememberToken()->comment('リメンバートークン'); $table->dateTime('created_at')->nullable()->comment('作成日時'); $table->dateTime('updated_at')->nullable()->comment('更新日時'); $table->softDeletes()->comment('削除日時'); $table->tableComment('ユーザー'); }); } };
在导出之前运行迁移。
$ php artisan migrate $ php artisan ddl:export
导出验证规则
$ php artisan ddl:rules
输出到 /config/rules.php
return [ 'users' => [ 'id' => ['integer', 'required'], 'name' => ['string', 'required', 'max:255'], 'email' => ['string', 'required', 'max:255'], 'email_verified_at' => ['date', 'nullable'], 'password' => ['string', 'required', 'max:255'], 'remember_token' => ['string', 'nullable', 'max:100'], 'created_at' => ['date', 'nullable'], 'updated_at' => ['date', 'nullable'], 'deleted_at' => ['date', 'nullable'], ], ];
导出翻译文件
$ php artisan ddl:trans
输出到 /resources/lang/ja/columns.php
return [ 'users' => [ 'id' => 'ID', 'name' => '氏名', 'email' => 'メールアドレス', 'email_verified_at' => 'メール認証日時', 'password' => 'パスワード', 'remember_token' => 'リメンバートークン', 'created_at' => '作成日時', 'updated_at' => '更新日時', 'deleted_at' => '削除日時', ], ];