定制 rozsazoltan/illuminate-blueprint-preserve 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

rozsazoltan/illuminate-blueprint-preserve

最新稳定版本:v0.0.2

Composer 安装命令:

composer require rozsazoltan/illuminate-blueprint-preserve

包简介

Automatically preserve the column settings when change a column in a migration

README 文档

README

Rose Production

illuminate-blueprint-preserve

Note

I explained the working principle of the Blueprint::column macro included in the package in a StackOverflow question. The main goal was to carry forward the logic retained up until the older Laravel 10.

Getting Started

composer require rozsazoltan/illuminate-blueprint-preserve

Usage

I will demonstrate the simplification provided by the package based on the modification mentioned in the Laravel documentation.

For example, imagine you have a migration that creates a votes column with the unsigned, default, and comment attributes:

Schema::create('users', function (Blueprint $table) {
    $table->integer('votes')->unsigned()->default(1)->comment('The vote count');
});

Later, you write a migration that changes the column to be nullable as well:

Schema::table('users', function (Blueprint $table) {
    $table->integer('votes')->nullable()->change();
});

In Laravel 10, this migration would retain the unsigned, default, and comment attributes on the column. However, in Laravel 11, the migration must now also include all of the attributes that were previously defined on the column. Otherwise, they will be dropped:

Schema::table('users', function (Blueprint $table) {
    $table->integer('votes')
        ->unsigned()
        ->default(1)
        ->comment('The vote count')
        ->nullable()
        ->change();
});

However, with my column macro, if I only want to modify the nullable on an existing column and keep all other attributes intact, the modification would look like this:

Schema::table('users', function (Blueprint $table) {
    $table->column('votes')->nullable();
});

Informations

  • There is no need to call change() separately when using the column macro.
  • The set values can be overridden and will take effect when the migration is executed.

Change type

Schema::table('users', function (Blueprint $table) {
    $table->column('votes')->type('float');
});

Reverting nullable

Schema::table('users', function (Blueprint $table) {
    $table->column('votes')->nullable(false);
});

Reverting auto increment

Schema::table('users', function (Blueprint $table) {
    $table->column('votes')->autoIncrement(false);
});

Other

All other functions that already work, such as default, comment, etc., continue to function as expected.

Support

I greatly appreciate your support for my efforts, whether through contributions, bug reports, sharing, starring, an upvote on Stack Overflow, or anything else that comes to mind.

License

All rights reserved as specified in the LICENSE file! This project can be considered reusable, copyable, and/or distributable, provided that the original public repository link is included in the source code and made visible to those who use the product that incorporates this source code/package.

统计信息

  • 总下载量: 1
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-11-30