GithubHelp home page GithubHelp logo

mybizna / automigrator Goto Github PK

View Code? Open in Web Editor NEW
3.0 1.0 0.0 97 KB

Declare database migrations and factory definitions inside Laravel models.

Home Page: https://mybizna.com

PHP 100.00%
automigrate erp laravel laravel-framework laravel-modular mybizna automigrator

automigrator's Introduction

Automigrator

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

Running the automigrator: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 automigrator: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 mybizna/automigrator

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 Mybizna\Automigrator\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 automigrator: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 automigrator: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 automigrator:resource {name} {--m|--model}

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

automigrator's People

Contributors

dedanirungu avatar legodion avatar

Stargazers

AlexDevBr avatar  avatar Jona Goldman avatar

Watchers

Kostas Georgiou avatar

Forkers

demoraisj

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.