Support Laravel Version: Laravel 8, Laravel 9, Laravel 10, Laravel 11 With Latest All Version Support.
In Laravel you can rename a column in a migration using the `change()` method provided by the Schema Builder. Here’s how you can rename a column in a migration:
use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; class RenameColumnNameInTable extends Migration { public function up() { Schema::table('your_table_name', function (Blueprint $table) { $table->renameColumn('old_column_name', 'new_column_name'); }); } public function down() { Schema::table('your_table_name', function (Blueprint $table) { $table->renameColumn('new_column_name', 'old_column_name'); }); } }
Replace `’your_table_name‘` with the actual name of your table, `’old_column_name‘` with the current name of the column you want to rename, and `’new_column_name’` with the new name you want to assign to the column.
In the `up()` method, the `renameColumn()` method renames the specified column from `’old_column_name‘` to `’new_column_name‘`.
In the `down()` method, the same `renameColumn()` method is used to reverse the renaming operation in case you need to rollback the migration.
Once you have created the migration file, run the migration using the `php artisan migrate` command to apply the changes to your database schema.