invoate / console-commands
这是我的包 console-commands
1.0.1
2023-03-07 18:29 UTC
Requires
- php: ^8.1
- illuminate/contracts: ^9.0|^10.0
- spatie/laravel-package-tools: ^1.14.0
Requires (Dev)
- laravel/pint: ^1.0
- nunomaduro/collision: ^6.0
- orchestra/testbench: ^8.0
- pestphp/pest: ^1.21
- pestphp/pest-plugin-laravel: ^1.1
- phpunit/phpunit: ^9.5
- spatie/laravel-ray: ^1.26
This package is auto-updated.
Last update: 2024-09-16 20:08:53 UTC
README
这些是一些打包在一起的命令行,这样它们就不必在新的项目中重新创建。
安装
您可以通过 composer 安装此包
composer require invoate/console-commands
用法
Pivot Make 命令
Pivot Make 命令为交叉表生成迁移。可以按任意顺序传递表名,命令将按字母顺序排序。
php artisan make:pivot table1 table2
table1
和 table2
参数可以是现有的 Eloquent 模型或表名。Eloquent 模型的表名将自动解析。
php artisan make:pivot User Team
Schema::create('teams_users', function (Blueprint $table) { $table->foreignId('team_id')->constrained(); $table->foreignId('user_id')->constrained(); //.. });
默认情况下,命令生成外键,可以使用 --without-foreign-keys
标志禁用。
php artisan make:pivot User Team --without-foreign-keys
Schema::create('teams_users', function (Blueprint $table) { $table->integer('team_id'); $table->integer('user_id'); //.. });
默认情况下还生成时间戳列,可以使用 --without-timestamps
标志禁用这些。
php artisan make:pivot User Team --without-timestamps
可以使用 --columns
标志创建额外的列,它们必须按照 column_name:column_type
格式格式化。
php artisan make:pivot User Team --columns string:role,timestamp:expires_at
Schema::create('teams_users', function (Blueprint $table) { //.. $table->string('role'); $table->timestamp('expires_at'); //.. });
可以使用 --with-model
标志生成交叉 Eloquent 模型。
php artisan make:pivot User Team --model # INFO Migration [database/migrations/2023_02_20_153354_create_teams_users_table.php] created successfully. # INFO Model [app/Models/TeamUser.php] created successfully.
可选地,可以使用 --with-id
标志生成 id 列。默认情况下,这将生成一个 $table>id()
列,通过传递另一个 Laravel 支持的列类型(例如 --id-type ulid
)可以更改此列。
php artisan make:pivot User Team --with-id --id-type ulid
Schema::create('teams_users', function (Blueprint $table) { $table->ulid(); //.. });
如果您不希望为交叉表生成任何列,可以使用 --without-columns
标志。
php artisan make:pivot User Team --without-columns
Schema::create('teams_users', function (Blueprint $table) { // });
刷新
RefreshCommand
是 php artisan migrate:fresh --seed
的简单包装。
php artisan refresh
测试
composer test
鸣谢
许可证
MIT 许可证 (MIT)。有关更多信息,请参阅许可证文件。