定制 sonole/laravel-db-seed-rollback 二次开发

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

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

sonole/laravel-db-seed-rollback

最新稳定版本:v1.0.1

Composer 安装命令:

composer require sonole/laravel-db-seed-rollback

包简介

README 文档

README

Introduction
In the context of package development, particularly those involving database seeders, I propose the introduction of the --rollback option for the db:seed command. This feature complements the existing migrate:rollback command and offers a solution for efficient database seeding management.

The Problem
Currently, many projects rely on packages that utilize seeders to alter the database. However, when complications arise, such as errors, changes in requirements, or the need to remove packages, there is a lack of streamlined mechanisms to revert these seeding changes. While the migrate:rollback command helps with migrations, the absence of a corresponding option for seeders presents challenges in complex projects where multiple custom packages are involved.

The Solution
By introducing the --rollback option for the db:seed command, package developers and maintainers can now address these issues.

Use Case
Just run db:seed with the --rollback option and down() function will be invoked!

php artisan db:seed --class="Vendor\\Package\\Database\\Seeders\\UsersSeeder" --rollback 
#or
php artisan db:seed --rollback
namespace Vendor\Package\Database\Seeders

/** If your seeder does not extend the package's Seeder:
 * Sonole\LaravelDbSeedRollback\Illuminate\Database\Seeder
 * then a new temporary file will be created at database/seeders, and it will be deleted after down() execution. 
*/
use Illuminate\Database\Seeder;

class UsersSeeder extends Seeder
{
    /**
     * Seed the application's database.
     */
    public function run(): void
    {
         //\App\Models\User::factory(10)->create();

        // \App\Models\User::factory()->create([
        //     'name' => 'Test User',
        //     'email' => 'test@example.com',
        // ]);
    }

    /**
     * Reverse the effects of the database seeding operation.
     */
    public function down(): void
    {
        \App\Models\User::where('email', 'foo@bar.com')->delete();
    }
}

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-11-02

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固