ItSolutionStuff.com

How to Change Table Name using Laravel Migration?

By Hardik Savani • April 16, 2024
Laravel

Hi All,

Today, i will let you know example of laravel migration rename table name. it's simple example of change table name in laravel migration. i explained simply about change table name using migration laravel. i explained simply step by step rename table in laravel migration.

You just see example of change table name using migration in laravel 6, laravel 7, laravel 8, laravel 9, laravel 10 and laravel 11.

We can easily rename table name using Schema rename method. so let's see bellow syntax and example as bellow:

Syntax:

Schema::rename('old_table_name', 'new_table_name');

Example:

<?php

use Illuminate\Support\Facades\Schema;

use Illuminate\Database\Schema\Blueprint;

use Illuminate\Database\Migrations\Migration;

class ChangePostsTableName extends Migration

{

/**

* Run the migrations.

*

* @return void

*/

public function up()

{

Schema::rename('posts', 'articales');

}

/**

* Reverse the migrations.

*

* @return void

*/

public function down()

{

}

}

I hope it can help you...

Tags: Laravel
Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

How to Change Column Name and Data Type in Laravel Migration?

Read Now →

How to Create Table using Migration in Laravel?

Read Now →

How to Write PHP Code in Laravel Blade?

Read Now →

How to Create URL Shortener using Laravel?

Read Now →

How to Drop Foreign Key Constraint in Laravel Migration?

Read Now →

How to Get Query Strings Value in Laravel?

Read Now →

How to Add MySQL Trigger from Migration in Laravel?

Read Now →

How to Set URL without Http of Other Site in Laravel?

Read Now →