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:
In this post we will learn how to add watermark on image in laravel 8. here we will see example of laravel 8 add waterma...
Jun-23-2021
In today's digital age, where security is paramount, user authentication has become a cornerstone concern for web ap...
Aug-21-2023
As we know Laravel 9 was officially released yesterday with many new functionalities like Symfony 6.0 components, Symfon...
Feb-10-2022
In this article, we will see how to convert a laravel query to an SQL query. Many times we required laravel query builde...
Oct-27-2022