Migrations
Migrations are version control for your database schema. Generate with php artisan make:migration.
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create("posts", function (Blueprint $table) {
$table->id();
$table->foreignId("user_id")->constrained()->cascadeOnDelete();
$table->string("title", 255);
$table->text("body")->nullable();
$table->string("status")->default("draft");
$table->timestamp("published_at")->nullable();
$table->boolean("is_featured")->default(false);
$table->softDeletes();
$table->timestamps();
});
}
public function down(): void
{
Schema::dropIfExists("posts");
}
};Schema Builder Methods
Schema::create("table", fn (Blueprint $t) => ...);
Schema::table("table", fn (Blueprint $t) => ...);
Schema::rename("from", "to");
Schema::drop("table");
Schema::dropIfExists("table");
Schema::hasTable("table");
Schema::hasColumn("table", "column");Column Modifiers
$table->string("email")->unique();
$table->string("slug")->index();
$table->unsignedBigInteger("views")->default(0);
$table->string("color", 7)->nullable();
$table->text("bio")->charset("utf8mb4");
// Laravel 13: ULID support
$table->ulid("id")->primary();
// Laravel 13: Vector column type (for AI/embeddings)
$table->vector("embedding", 1536);