承接 mylesduncanking/laravel-simple-migration 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

mylesduncanking/laravel-simple-migration

最新稳定版本:v2.1.8

Composer 安装命令:

composer require mylesduncanking/laravel-simple-migration

包简介

Streamlined class for simple migrations within Laravel

README 文档

README

📦 Installation

composer require mylesduncanking/laravel-simple-migration

❓ Why Use This Package?

Laravel's migrations are powerful but can become verbose and repetitive, especially for simple table structures or frequent seed/migrate workflows.

Laravel Simple Migration helps you:

  • Write cleaner, array-based migration definitions
  • Avoid boilerplate like ->after() and ->index()
  • Automatically run seeders alongside migrations
  • Maintain clarity and control with a minimal syntax layer

Perfect for rapid prototyping, internal tools, or any dev who loves less noise and more flow.

🚀 Getting Started

This package builds on Laravel's native migration system. If you're familiar with Laravel migrations, this will feel familiar.

To create a simple migration:

php artisan make:simple-migration your_migration_name

Your migration file will contain a $migration array for defining schema changes.

Format

protected array $migration = [
    'TABLE_NAME' => [
        'COLUMN_NAME' => ['MODIFIERS'],
        // Additional columns...
    ],
    // Additional tables...
];

🔁 Auto-After Functionality

To save time when adding multiple columns, this package adds them sequentially by default. This removes the need for ->after('column').

To disable this:

php artisan vendor:publish --tag=simplemigration

Then set config/simplemigration.php > auto_after to false.

⚡ Auto-Index Functionality

By default, any column ending in _id will automatically get an ->index() modifier.

Customize this behavior:

php artisan vendor:publish --tag=simplemigration

Then edit the regex rules in config/simplemigration.php > auto_index.

To exclude a specific column from auto-indexing, add noIndex in its modifiers array.

🌱 Seeder Functionality

Table creations or updates often require seeders. This package uses Laravel's migration tracking to automatically run seeders during the up() method.

This package assumes that seeders are stored under \Seeds namespace and have a class name that starts with a capital letter and ends with Seeder.

protected array $seeders = [
    'roles', // This will translate to (new \Seeds\RolesSeeder())->run()
];

Note: Seeders only run during up() by default. To run seeders during rollback (down()), use beforeDown() or afterDown() and call runSeeder($seederName) manually.

📘 Table Naming Convention

If a table includes an id or uuid column, it is assumed to be a new table. Otherwise, the table is assumed to be updated.

To explicitly define the action, use:

  • create:table_name
  • update:table_name

Or adjust assumptions globally:

config/simplemigration.php > type_assumptions

Example

protected array $migration = [
    'table_to_be_created' => [
        'id',
        'name',
        'date:dob' => ['nullable'],
        'timestamps',
    ],

    'table_to_be_updated' => [
        'name' => ['after:id']
    ],

    'create:pivot_table' => [
        'foreignId:key_1' => ['index'],
        'foreignId:key_2' => ['index'],
    ],
];

🏷️ Column Key Format

Format keys as {type}:{column}.

Examples:

  • integer:quantity
  • set:status
  • foreignId:user_id
  • date:dob => ['nullable']

✅ Supported Modifiers

You can use all default Laravel column modifiers in array format:

  • nullable
  • default:value
  • unique
  • index
  • after:other_column
  • comment:some text
  • noIndex (custom)

✨ Helper Methods

beforeDown()

Hook to perform actions before the down() method runs.

afterDown()

Hook to perform actions after the down() method runs.

runSeeder($seeder)

Run a seeder manually.

✏️ Example Seeder Triggered in Migration

protected array $migration = [
    'roles' => [
        'id',
        'name',
    ],
];

protected array $seeders = [
    'Role'
];

This will run RoleSeeder when the migration is applied.

📁 Config File

To customize assumptions and toggles:

php artisan vendor:publish --tag=simplemigration

Edit config/simplemigration.php to:

  • Enable/disable auto-index or auto-after
  • Add custom regex rules
  • Set type assumptions for new vs update

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-07-12