Tips & Tricks about Laravel Migration

How to Create Migrations in Laravel

You can create a migration file using the Laravel make migration command. You need to specify a meaningful filename like below:

php artisan make:migration create_companies_table
php artisan make:migration create_companies_table --create==companies
php artisan make:migration modify_companies_table --table==companies
php artisan make:model Company -m
php artisan migrate
php artisan migrate --pretend
php artisan migrate:rollback
php artisan migrate:rollback --step=5
php artisan migrate:reset
php artisan migrate:resetphp artisan migrate
php artisan migrate:fresh
if (Schema::hasTable('users')) {    //Create Table code goes here.}
Schema::rename('old_table_name', 'new_table_name);
Schema::dropIfExists('companies');
$table->engine = 'InnoDB';

$table->string(‘type’)->default(‘Default Value’);

$table->string(‘type’)->nullable()

$table->integer(‘user_id’)->index()

$table->string(‘name’)->unique();

$table->string(‘name’, 50)->change()

$table->renameColumn(‘old_column’, ‘new_column’);

$table->dropColumn(‘column_name’)

$table->string(‘type’)->nullable()->after(‘name’);

$table->string(‘type’)->nullable()->first()
if (Schema::hasColumn('type')) {
//Create Column code goes here.
}

Freelancer Developer.