xxxxxxxxxx
Firstly, use CLI command to create a migration:
php artisan make:migration rename_table
Now, in the up method of the new migration class, use the rename method to change table name:
Schema::rename('old_table_name', 'new_table_name');
Next, execute the migration command:
php artisan migrate
xxxxxxxxxx
# first must run this command
composer require doctrine/dbal
# then try
Schema::table('users', function (Blueprint $table) {
$table->renameColumn('from', 'to');
});
#then migrate it
php artisan migrate
xxxxxxxxxx
# command line terminal
composer require doctrine/dbal
php artisan make:migration update_oldFileName_table
# write this in your migration file. Change from and to by your column info
public function up()
{
Schema::table('delivery_credit', function (Blueprint $table) {
$table->renameColumn('from','to');
});
}
}
public function down()
{
Schema::table('delivery_credit', function (Blueprint $table) {
$table->renameColumn('to','from');
});
}
# in your terminal
php artisan migrate
xxxxxxxxxx
php artisan make:migration rename_author_id_in_posts_table --table=posts
Composer Package to Install to use rename column
xxxxxxxxxx
composer require doctrine/dbal
xxxxxxxxxx
public function up()
{
Schema::table('posts', function (Blueprint $table) {
$table->renameColumn('author_ID', 'user_id');
});
}
xxxxxxxxxx
public function down()
{
Schema::table('posts', function (Blueprint $table) {
$table->renameColumn('user_id', 'author_ID');
});
}