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
Google Recaptcha Example In Laravel
Google Recaptcha Example In La...

 In this tutorial I will teach you about Google Recaptcha, Google Recaptcha is used for advanced risk analysis...

Read More

Jun-10-2020

Laravel tips: DB Models and Eloquent - 2023
Laravel tips: DB Models and El...

Welcome to the fourth installment of our "Laravel Tips: DB Models and Eloquent" series. In this article, we co...

Read More

Oct-18-2023

How To Add Summernote Editor In Laravel
How To Add Summernote Editor I...

In this tutorial, I will let you know how to use summernote editor in laravel, In laravel or PHP many editors are a...

Read More

Jun-17-2020

How to Validate Reactive Form in Angular 17
How to Validate Reactive Form...

Hello developer, In this article, we'll see how to validate a reactive form in angular 17. Reactive forms...

Read More

Mar-27-2024