Your IP : 216.73.216.79


Current Path : /var/www/html/dyna-laravel.blunetdev.com/modules/system/console/
Upload File :
Current File : /var/www/html/dyna-laravel.blunetdev.com/modules/system/console/CreateMigration.php

<?php namespace System\Console;

use Str;
use System\Console\BaseScaffoldCommand;

/**
 * Scaffolds a new migration file
 *
 * @TODO:
 * - Add flag to either create a new version automatically in version.yaml or
 *   add the migration to a specific version, would also put the migration in
 *   a version specific folder
 */
class CreateMigration extends BaseScaffoldCommand
{
    /**
     * @var string|null The default command name for lazy loading.
     */
    protected static $defaultName = 'create:migration';

    /**
     * @var string The name and signature of this command.
     */
    protected $signature = 'create:migration
        {plugin : The name of the plugin. <info>(eg: Winter.Blog)</info>}
        {name : The name of the migration to generate. <info>(eg: CreatePostTable)</info>}
        {--f|force : Overwrite existing files with generated files.}
        {--model= : The model to create a migration for. <info>(eg: Post)</info>}
        {--table= : The table to migrate, defaults to autogenerated from the provided model. <info>(eg: winter_blog_posts)</info>}
        {--c|create : Generate a migration that creates the specified table}
        {--u|update : Generate a migration that updates the specified table}
    ';

    /**
     * @var string The console command description.
     */
    protected $description = 'Creates a new migration.';

    /**
     * @var array List of commands that this command replaces (aliases)
     */
    protected $replaces = [
        'make:migration',
    ];

    /**
     * @var string The type of class being generated.
     */
    protected $type = 'Migration';

    /**
     * @var array A mapping of stubs to generated files.
     */
    protected $stubs = [
        'scaffold/migration/create_table.stub' => 'updates/create_{{snake_plural_name}}_table.php',
    ];

    /**
     * Prepare variables for stubs.
     */
    protected function prepareVars(): array
    {
        $parts = explode('.', $this->getPluginIdentifier());
        $plugin = array_pop($parts);
        $author = array_pop($parts);
        $name = $this->getNameInput();
        $table = $this->option('table');
        $model = $this->option('model');

        if (empty($table) && !empty($model)) {
            $modelClass = "\\{$author}\\{$plugin}\Models\\{$model}";
            if (class_exists($modelClass)) {
                $table = (new $modelClass)->getTable();
            }
        }

        $this->error("create:migration has not been implemented yet");

        return [
            'name' => $name,
            'author' => $author,
            'plugin' => $plugin,
        ];
    }
}