eelcol/laravel-blueprint-group

Laravel Blueprint group 扩展

1.1.0 2020-12-25 12:04 UTC

README

有时候,你可能想在迁移文件中分组语句。例如,当你想向一个表添加3个新列,而不想在每个语句上指定 ->after('...')。现在你可以使用分组方法了!

示例

让我们以下面的迁移文件为例

Schema::table('table', function (Blueprint $table) {
            
	$table->string('new_column_a')->nullable()->after('some_old_column');
	$table->string('new_column_b')->nullable()->after('new_column_a');
	$table->string('new_column_c')->nullable()->after('new_column_b');

});

这可以按照以下方式分组

Schema::table('table', function (Blueprint $table) {

	$table->group(function($group) {
            
		$group->string('new_column_a');
		$group->string('new_column_b');
		$group->string('new_column_c');

	})->nullable()->after('some_old_column');

});

安装

使用 composer 需要此包。

composer require eelcol/laravel-blueprint-group

Laravel 5.5 使用包自动发现功能,因此不需要你手动添加 ServiceProvider。

如果你不使用自动发现,请将 ServiceProvider 添加到 config/app.php 文件中的 providers 数组中

Eelcol\LaravelBlueprintGroup\BlueprintGroupServiceProvider::class,