### Install Laravel Migrations Generator via Composer Source: https://github.com/kitloong/laravel-migrations-generator/blob/7.x/docs/index.md This command installs the Laravel Migrations Generator package as a development dependency using Composer. It ensures the package is available for your project. ```bash composer require --dev kitloong/laravel-migrations-generator ``` -------------------------------- ### Example of a Squashed Migration File Source: https://github.com/kitloong/laravel-migrations-generator/blob/7.x/docs/options/squash.md This PHP code represents a single migration file generated using the --squash option. It includes the 'up' method to create 'comments' and 'users' tables and set up a foreign key relationship, and the 'down' method to reverse these changes. ```php bigIncrements('id'); ... }); Schema::create('users', function (Blueprint $table) { $table->bigIncrements('id'); ... }); Schema::table('comments', function (Blueprint $table) { $table->foreign(['user_id'])->references(['id'])->on('users')->onUpdate('restrict')->onDelete('restrict'); }); } /** * Reverse the migrations. */ public function down(): void { Schema::table('comments', function (Blueprint $table) { $table->dropForeign('comments_user_id_foreign'); }); Schema::dropIfExists('users'); Schema::dropIfExists('comments'); } }; ``` -------------------------------- ### Database Configuration Example (PHP) Source: https://github.com/kitloong/laravel-migrations-generator/blob/7.x/docs/options/use-db-collation.md This PHP code snippet shows a typical configuration for a MySQL connection within Laravel's `config/database.php` file. It highlights the `charset` and `collation` settings that are used by default when migrations are generated without the `--use-db-collation` flag. When the flag is used, these settings are dynamically applied to the generated migration files. ```php // config/database.php return [ 'connections' => [ 'mysql' => [ ... 'charset' => 'utf8mb4', 'collation' => 'utf8mb4_unicode_ci', ], ], ]; ``` -------------------------------- ### Enable Facades in Lumen Source: https://github.com/kitloong/laravel-migrations-generator/blob/7.x/docs/index.md This PHP snippet demonstrates how to enable facades in a Lumen application by uncommenting the appropriate line in the `bootstrap/app.php` file. This is a prerequisite for using facade-based features. ```php $app->withFacades(); ``` -------------------------------- ### Register Migrations Generator Service Provider for Lumen Source: https://github.com/kitloong/laravel-migrations-generator/blob/7.x/README.md In Lumen projects, you need to manually register the service provider within the `Register Service Providers` section of `bootstrap/app.php`. ```php $app->register( KitLoong\MigrationsGenerator\MigrationsGeneratorServiceProvider::class ); ``` -------------------------------- ### Query Migrations by Batch Number (SQL) Source: https://github.com/kitloong/laravel-migrations-generator/blob/7.x/docs/options/log-with-batch.md This SQL query demonstrates how to retrieve migration information from the 'migrations' table based on a specific batch number. It shows which migration files were logged under a given batch, useful for verifying the --log-with-batch option's effect. ```sql SELECT migration FROM `migrations` WHERE batch = 0; +----------------------------------------------------------+ | migration | +----------------------------------------------------------+ | 2024_10_08_083231_create_users_table.php | | 2024_10_08_083231_create_comments_table.php | | 2024_10_08_083232_add_foreign_keys_to_comments_table.php | +----------------------------------------------------------+ ``` -------------------------------- ### Generate Migrations Using a Specific Database Connection (Artisan) Source: https://github.com/kitloong/laravel-migrations-generator/blob/7.x/README.md If you are not using the default database connection, specify the connection name using the `--connection` flag. ```bash php artisan migrate:generate --connection="connection_name" ``` -------------------------------- ### Generate Migrations for Specific Tables (Artisan) Source: https://github.com/kitloong/laravel-migrations-generator/blob/7.x/README.md Use this command to generate migration files only for a specified list of tables. Separate table names with commas. ```bash php artisan migrate:generate --tables="table1,table2,table3,table4,table5" ``` -------------------------------- ### Generate All Migrations using Artisan Source: https://github.com/kitloong/laravel-migrations-generator/blob/7.x/docs/usage.md This command generates migration files for all tables in the database. It prompts the user to confirm logging migrations and to specify a batch number. The generated files include schema definitions and foreign key constraints. ```bash php artisan migrate:generate ``` -------------------------------- ### Specify Tables for Migration Generation (Bash) Source: https://github.com/kitloong/laravel-migrations-generator/blob/7.x/docs/options/tables.md Use the --tables option with the `migrate:generate` Artisan command to generate migrations for a comma-separated list of tables or views. This allows for targeted migration creation, excluding other database objects. Dependencies include the Laravel framework and a configured database connection. ```bash php artisan migrate:generate --tables="users,posts,comments" ``` -------------------------------- ### Generate Migrations with Database Collation (Bash) Source: https://github.com/kitloong/laravel-migrations-generator/blob/7.x/docs/options/use-db-collation.md This command generates migration files while including the database's current collation and character set settings. This ensures that new tables created via these migrations will adhere to the database's existing collation, as defined in config/database.php. This option overrides the default behavior where migrations are generated without explicit collation settings. ```bash php artisan migrate:generate --use-db-collation ``` -------------------------------- ### Combine Migrations with --squash Option Source: https://github.com/kitloong/laravel-migrations-generator/blob/7.x/docs/options/squash.md This command generates a single migration file by combining all previous migrations. It's useful for reducing the number of migration files in your project. This functionality is part of the Laravel Migrations Generator package. ```bash php artisan migrate:generate --squash ``` -------------------------------- ### Generated Migration Schema with Collation (PHP) Source: https://github.com/kitloong/laravel-migrations-generator/blob/7.x/docs/options/use-db-collation.md This PHP code snippet demonstrates the structure of a migration file generated using the `--use-db-collation` option. It explicitly sets the `collation` and `charset` properties on the schema blueprint, ensuring that the created table uses the database's configured collation. This contrasts with migrations generated without the flag, which would rely solely on the application's database configuration. ```php Schema::create('users', function (Blueprint $table) { $table->collation = 'utf8mb4_unicode_ci'; $table->charset = 'utf8mb4'; $table->bigIncrements('id'); ... }); ``` -------------------------------- ### Enable Default Foreign Key Naming Convention (Bash) Source: https://github.com/kitloong/laravel-migrations-generator/blob/7.x/docs/options/default-fk-names.md This command-line option instructs the migration generator to use Laravel's default naming convention for foreign keys. This is useful for maintaining consistency across different database systems and ensuring that generated migrations adhere to project standards. ```bash php artisan migrate:generate --default-fk-names ``` -------------------------------- ### Specify Database Connection for Migration Generation Source: https://github.com/kitloong/laravel-migrations-generator/blob/7.x/docs/options/connection.md The `--connection` option allows you to specify which database connection to use when generating migrations. If not provided, Laravel's default connection is used. This is useful for applications with multiple database configurations. ```bash php artisan migrate:generate --connection="secondary" ``` -------------------------------- ### Specify Migration Log Batch with --log-with-batch (Bash) Source: https://github.com/kitloong/laravel-migrations-generator/blob/7.x/docs/options/log-with-batch.md The --log-with-batch option in the migrate:generate command allows you to bypass the interactive prompt and directly specify the batch number for logging generated migrations. This is useful for automating migration logging or ensuring a specific batch number is used. The default batch number is 0. ```bash php artisan migrate:generate --log-with-batch=0 ``` -------------------------------- ### Customize Table Migration Filename Pattern (Bash) Source: https://github.com/kitloong/laravel-migrations-generator/blob/7.x/docs/options/table-filename.md This command demonstrates how to use the `--table-filename` option to specify a custom naming pattern for generated table migration files. The pattern uses placeholders like `[datetime]` for the timestamp and `[name]` for the table name. This allows for more organized or standardized migration file naming conventions. ```bash php artisan migrate:generate --table-filename="[datetime]_create_mysql_[name]_table.php" ``` -------------------------------- ### Register Migrations Generator Service Provider in Lumen Source: https://github.com/kitloong/laravel-migrations-generator/blob/7.x/docs/index.md This PHP snippet shows how to register the Migrations Generator Service Provider within the `bootstrap/app.php` file of a Lumen application. This makes the generator's functionality available. ```php $app->register(KitLoongMigrationsGeneratorMigrationsGeneratorServiceProvider::class); ``` -------------------------------- ### Specify Custom Migration Template Path (Bash) Source: https://github.com/kitloong/laravel-migrations-generator/blob/7.x/docs/options/template-path.md The --template-path option allows specifying a custom directory for migration templates. This enables users to define their own migration generation stubs. Ensure the custom stub includes placeholders like {{ use }}, {{ up }}, and {{ down }}. ```bash php artisan migrate:generate --template-path="custom/templates" ``` -------------------------------- ### Create Comments Table Migration Source: https://github.com/kitloong/laravel-migrations-generator/blob/7.x/docs/usage.md This PHP migration file defines the schema for the 'comments' table, including columns for user ID, title, comment, and timestamps. It also sets up an index and foreign key constraint for the user_id. ```php bigIncrements('id'); $table->unsignedBigInteger('user_id')->index(); $table->string('title'); $table->string('comment')->unique(); $table->timestamps(); }); } /** * Reverse the migrations. */ public function down(): void { Schema::dropIfExists('comments'); } }; ``` -------------------------------- ### Ignore Tables When Generating Migrations (Artisan) Source: https://github.com/kitloong/laravel-migrations-generator/blob/7.x/README.md This command generates migrations for all tables except those specified in the `--ignore` flag. Separate table names with commas. ```bash php artisan migrate:generate --ignore="table3,table4,table5" ``` -------------------------------- ### Database Schema Definition with Specific Connection Source: https://github.com/kitloong/laravel-migrations-generator/blob/7.x/docs/options/connection.md Demonstrates how to explicitly define a database connection within Laravel's Schema builder for creating or dropping tables. This ensures operations are performed on the intended database. ```php // Up Schema::connection('secondary')->create('users', function (Blueprint $table) { $table->bigIncrements('id'); ... }); // Down Schema::connection('secondary')->dropIfExists('users'); ``` -------------------------------- ### Retrieve Database Connection Names Source: https://github.com/kitloong/laravel-migrations-generator/blob/7.x/docs/options/connection.md This PHP snippet shows how to programmatically retrieve an array of all configured database connection names within a Laravel application. This is helpful for identifying available connections for the `--connection` option. ```php array_keys(config('database.connections')) ``` -------------------------------- ### Generated Schema for Foreign Key (PHP) Source: https://github.com/kitloong/laravel-migrations-generator/blob/7.x/docs/options/default-fk-names.md Demonstrates how the 'comments' table schema with a foreign key constraint is translated into a Laravel migration file when the --default-fk-names option is used. The generated code uses the fluent schema builder to define the foreign key relationship. ```php Schema::table('comments', function (Blueprint $table) { ... $table->foreign('user_id')->references('id')->on('users'); }); ``` -------------------------------- ### Create Users Table Migration Source: https://github.com/kitloong/laravel-migrations-generator/blob/7.x/docs/usage.md This PHP migration file defines the schema for the 'users' table, including columns like id, name, email, password, and timestamps. It's generated by the migrations generator based on an existing table structure. ```php bigIncrements('id'); $table->string('name')->comment('comment'); $table->string('email')->unique(); $table->timestamp('email_verified_at')->nullable(); $table->string('password'); $table->rememberToken(); $table->timestamps(); }); } /** * Reverse the migrations. */ public function down(): void { Schema::dropIfExists('users'); } }; ``` -------------------------------- ### Specify Migration Output Path using Artisan CLI Source: https://github.com/kitloong/laravel-migrations-generator/blob/7.x/docs/options/path.md This command-line interface option allows users to designate a specific directory for generated Laravel migration files. By default, migrations are saved in 'database/migrations'. This option overrides that default. ```bash php artisan migrate:generate --path="custom/migrations" ``` -------------------------------- ### Specify Migration Date with --date Option (Bash) Source: https://github.com/kitloong/laravel-migrations-generator/blob/7.x/docs/options/date.md The --date option allows specifying a custom date for generated migration files using the `php artisan migrate:generate` command. The date format should be compatible with Carbon::parse. This option affects the primary migration timestamp and adds a one-second increment for related files like views, procedures, and foreign keys. ```bash php artisan migrate:generate --date="2024-10-08 12:30:00" ``` -------------------------------- ### Add Foreign Keys to Comments Table Migration Source: https://github.com/kitloong/laravel-migrations-generator/blob/7.x/docs/usage.md This PHP migration file is responsible for adding foreign key constraints to the 'comments' table, linking it to the 'users' table. It includes a `up` method to add the foreign key and a `down` method to drop it. ```php foreign(['user_id'])->references(['id'])->on('users')->onUpdate('restrict')->onDelete('restrict'); }); } /** * Reverse the migrations. */ public function down(): void { Schema::table('comments', function (Blueprint $table) { $table->dropForeign('comments_user_id_foreign'); }); } }; ``` -------------------------------- ### Generate Migration for User-Defined Type Column (PHP) Source: https://github.com/kitloong/laravel-migrations-generator/blob/7.x/docs/udt-columns.md This PHP code demonstrates how to create a migration that adds a column with a user-defined type to a database table. It uses Laravel's Schema and DB facade. The generated column is always added at the end of the table. ```php public function up() { Schema::create('table', function (Blueprint $table) { ... }); DB::statement("ALTER TABLE table ADD column custom_type NOT NULL"); } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.