Migrations: When to use index()?

Posted 4 months ago by DoeJohn

Should I addindex() for every field? Or just use it on foreign keys? Or?

For example, here's one migration:

    public function up()
        Schema::create('posts', function (Blueprint $table) {





            $table->unique(['category_id', 'slug']);

Which fields in this migration should be indexed? For example, I always add them on foreign keys:


Is this wrong (to always use index() on foreign keys)?

Would you index some other fields in this migration? If yes, which one?

Please sign in or create an account to participate in this conversation.

Laracasts Mascot

Hi, Have We Met Yet?

Did you know that, in addition to the forum, Laracasts includes well over 1000 lessons on modern web development? All for the price of one lunch out per month.

Sign Me Up


Reply to

Use Markdown with GitHub-flavored code blocks.