Migrations in PHP

From the Laravel cheat sheet · Migrations & Schema · verified Jul 2026

Migrations

Creating and managing database migrations

php
// Create migration
php artisan make:migration create_posts_table

// Migration structure
public function up()
{
    Schema::create('posts', function (Blueprint $table) {
        $table->id();
        $table->string('title');
        $table->text('body');
        $table->foreignId('user_id')->constrained();
        $table->timestamps();
    });
}

public function down()
{
    Schema::dropIfExists('posts');
}
💡 Use foreign key constraints for referential integrity
⚡ Add indexes to columns used in WHERE clauses
📌 Use softDeletes() for keeping deleted records
🔥 Always define down() method for rollbacks
Back to the full Laravel cheat sheet