Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

EliasSoares's avatar

FULLTEXT Indexes at migrations

How can I create an Fulltext Index for a column in my migration file?

Didn't found anything about this in Laravel Docs...

0 likes
9 replies
bestmomo's avatar

That ?

$table->text('description')->unique();
EliasSoares's avatar

Will it work for

$table->string('column', 1024)->unique();

?

RachidLaasri's avatar

This will not work, because the max is 767

$table->string('column', 1024)->unique();
EliasSoares's avatar

Exactly. For fields with length greater then 767 characters, I need to use "FULLTEXT" index. It's different from "UNIQUE" index.

Is there any way to create fulltext indexes in Laravel Schema Builder? Or I will need to create it with a SQL query?

drubin's avatar
drubin
Best Answer
Level 1

You have to use SQL statements, but you can put them in your migration:

DB::statement('ALTER TABLE posts ADD FULLTEXT full(name, content)');
12 likes
chiefguru's avatar

This doesn't work if you have table prefixes, I had to write

DB::statement('ALTER TABLE '.DB::getTablePrefix().'laravel_fulltext ADD FULLTEXT fulltext_title(indexed_title)');

to get the right table prefix.

Is there a better way?

Please or to participate in this conversation.