定制 will2therich/laravel-model-migrations 二次开发

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

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

will2therich/laravel-model-migrations

最新稳定版本:2.0.2

Composer 安装命令:

composer require will2therich/laravel-model-migrations

包简介

Declare database migrations and factory definitions inside Laravel models.

README 文档

README

LaravelModelMigrations

Laravel Automatic Model Migrations

This package is a continuation of legodion/lucid which is no longer available

This package allows you to declare database migrations and factory definitions inside of your Laravel models.

Running the lmm:migrate command will automatically apply any changes you've made inside your migration methods to the database via Doctrine DBAL. If using the HasNewFactory trait and definition method, it will use the returned array inside the definition method to seed with when using the -s option.

The lmm:migrate command will also run your file-based (traditional) Laravel migrations first, and then your model method migrations after. If you need your model-based migrations to run in a specific order, you may add a $migrationOrder property to your models with an integer value (default is 0).

Installation

Require this package via Composer:

composer require will2therich/laravel-model-migrations

Usage

Use the HasNewFactory trait, and declare migration and definition methods in your models:

use Faker\Generator;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Schema\Blueprint;
use will2therich\LaravelModelMigrations\Traits\HasNewFactory;

class MyModel extends Model
{
    use HasNewFactory;

    protected $guarded = [];
    protected $migrationOrder = 1; // optional

    public function migration(Blueprint $table)
    {
        $table->id();
        $table->string('name');
        $table->timestamp('created_at')->nullable();
        $table->timestamp('updated_at')->nullable();
    }

    public function definition(Generator $faker)
    {
        return [
            'name' => $faker->name(),
            'created_at' => $faker->dateTimeThisMonth(),
        ];
    }
}

Commands

Migrating

Apply the changes inside your migration methods to your database:

php artisan lmm:migrate {--f|--fresh} {--s|--seed}

Use the -f option for fresh migrations, and/or the -s option to run seeders afterwards.

Making Models

Create a model containing the migration and definition methods:

php artisan lmm:model {name} {--r|--resource}

Use the -r option to create a Laravel Nova resource for the model at the same time.

Making Nova Resources

Create a Laravel Nova resource without all the comments:

php artisan lmm:resource {name} {--m|--model}

Use the -m option to create a model for the Nova resource at the same time.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-04-26