How To Change Table Name Using Laravel 10 Migration

Websolutionstuff | Apr-28-2023 | Categories : Laravel

In this article, we will see how to change the table name using laravel 10 migration. Here, we will learn about the laravel 10 change table name using migration. You can rename the table with the help of migration. In laravel 10, provide rename() method for change the table name. 

So, let's see laravel 10 change table name migration, how to rename a table in laravel 10 migration, and how to rename an existing table in laravel 8, laravel 9, and laravel 10.

To rename an existing database table, use the rename method.

use Illuminate\Support\Facades\Schema;
 
Schema::rename($from, $to);

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 ChangeUsersTableName extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::rename('user', 'users');
    }
  
    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
          
    }
}

 


You might also like:

Recommended Post
Featured Post
How To Create User Roles And Permissions In Laravel 10
How To Create User Roles And P...

In this article, we will see how to create user roles and permissions in laravel 10. Here, we will learn about roles and...

Read More

Apr-03-2023

Carbon Add Months To Date In Laravel 9
Carbon Add Months To Date In L...

In this article, we will see carbon add months to date in laravel 9. Carbon provides the addMonth() and addMon...

Read More

Nov-18-2022

Character Count In Textarea
Character Count In Textarea

In this article, we will explain to you how to count characters from textarea. many times a client has requirements...

Read More

Jul-08-2020

jQuery After And Before Example
jQuery After And Before Exampl...

In this article I will give you example of jquery after() and before() method. The after() method inserts spec...

Read More

Dec-10-2021