I have tried this in my migration but it does not work as expected.
$table->string('key')->primary()->index();
I also tried to use chatgpt but no solutions were correct. So I hit brick wall debugging, I know its something obvious I am missing.
>Solution :
Welcome to SO, its been answered before but the simples way to index your column is to add this in a new migration, so firstly create a migration like
php artisan make:migration add_index_to_key_column_on_table
and in that migration
Schema::table('table', function (Blueprint $table) {
$table->index(['key']);
});