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 Toggle Dark and Light Mode using jQuery
How To Toggle Dark and Light M...

In this article, we will see how to toggle between dark and light modes using jquery. As per the current trend of web de...

Read More

Nov-24-2020

How To Restrict User Access From IP Address In Laravel 9
How To Restrict User Access Fr...

Imagine this: You've made a super cool website, and now you want to make sure only the right people can use it. That...

Read More

Jan-03-2023

Laravel whereDate and whereDay Example
Laravel whereDate and whereDay...

In this article, we will see laravel whereDate and whereDay examples. As you all know laravel provides many in...

Read More

Jan-21-2021

How to Create Login and Register in Node.js
How to Create Login and Regist...

As I embarked on my journey to develop a powerful web application, I realized the importance of a robust user authentica...

Read More

Oct-02-2023