Laravel Rename Table Column


Laravel Rename Table Column – The Laravel Rename Table Column is used to rename the table column.


Laravel Rename Table Column Using Migration | with full Example.

Let us understand how to use Laravel Rename Table Column Using Migration.

Full example of rename table column using migration.

Now here i am going to explain how to rename table column step by step.

First we have to create migration using artisan command like this.

php artisan make:migration create_Data_Table

Then we have to include Doctrine\DBAL into our project.

composer require doctrine/dbal
Laravel Rename Table Column

After successfull installation we can easily rename the table column like this:-

Migration File:-

Let’s look at a simple example.

<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class createDataTable extends Migration
{
public function up()
    {
        Schema::table('sonu1', function (Blueprint $table) {
            $table->renameColumn('id', 'Tutorials_id');
            $table->renameColumn('name', 'Tutorials_name');
           
        });
    }
public function down()
    {
        Schema::dropIfExists('sonu1');
    }
}

Finally run this migration through artisan command.

php artisan migrate create_Data_Table

Then you can see in your database table, column will be renamed.

Laravel Rename Table Column

Advertisements

Add Comment

📖 Read More