Laravel Migration Custom Index Name Example

About Us:

We are from free coder. We are a group of web developers who are passionate about web development. You can learn from us php, laravel, node js, vue js, react js and many other topic on web developement.
we are very happy to help you.
free coder

Today what you are going to learn:

Hello Brother,

In this article, we will talk about laravel migration change index name. we will help you to give lesson of laravel migration custom index name. you can see laravel custom index name migration. i explained simply about how to add custom index name in laravel migration. So, let's follow few step to create lesson of change index name laravel migration.

I will give you very simple lesson of how to change index name using migration in laravel 6, laravel 7 and laravel 8 version.

few days ago, i added one post, how to add index using laravel migration. in this post i will help you how to change index name using migration. let's see bellow lesson.

Create Migration Command:

php artisan make:migration create_items_table



use Illuminate\Database\Migrations\Migration;

use Illuminate\Database\Schema\Blueprint;

use Illuminate\Support\Facades\Schema;

class CreateItemsTable extends Migration



* Run the migrations.


* @return void


public function up()


Schema::create('items', function (Blueprint $table) {





$table->index(['title', 'created_at'], 'items_title_created_at_index_new');


$table->index(['title', 'created_at']);

Default Name Index Key Name will be : "items_title_created_at_index"





* Reverse the migrations.


* @return void


public function down()





by default it will take "items_title_created_at_index" index key name, but if you want to change your own then index function take another argument for custom name so i just rename it like "items_title_created_at_index_new". let's run seeder and see mysql layout.

run migration

php artisan migrate

thank you very much for following up with me.

Recent Posts

Related Posts