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 Store JSON Data In Database Laravel 9
How To Store JSON Data In Data...

In this article, we will see how to store JSON data in the database laravel 9. Laravel 9 stores JSON data in M...

Read More

Sep-28-2022

How to Create Login and Registration in Laravel 11
How to Create Login and Regist...

Hello developers! In this guide, We'll see how to create a login and registration page in laravel 11 using the larav...

Read More

Apr-15-2024

Laravel 9 Create Middleware For XSS Protection
Laravel 9 Create Middleware Fo...

In this article, we will see laravel 9 create middleware for XSS protection. Cross-site scripting is a type of...

Read More

Apr-30-2022

Laravel AJAX CRUD example
Laravel AJAX CRUD example

Today I will show you how to create ajax crud operations in laravel. In laravel 6/7 ajax crud operation, we can perform...

Read More

May-14-2020