← Laravel tutorial

Laravel

Migrations

A migration is a PHP class describing one change to your database schema, creating a table, adding a column.

Example: a migration that creates a table

// database/migrations/..._create_posts_table.php
public function up()
{
    Schema::create('posts', function (Blueprint $table) {
        $table->id();
        $table->string('title');
        $table->text('body');
        $table->timestamps();
    });
}
php artisan migrate

Running php artisan migrate applies every migration that hasn't run yet, in order, creating a posts table with id, title, body, created_at, and updated_at columns ($table->timestamps() adds the last two automatically). The real value here: your whole team's database structure stays in sync through version control, every migration file committed to the repo, instead of someone manually running ad hoc SQL that only they remember they ran.

Example
// database/migrations/..._create_posts_table.php
public function up()
{
    Schema::create('posts', function (Blueprint $table) {
        $table->id();
        $table->string('title');
        $table->text('body');
        $table->timestamps();
    });
}
Output
php artisan migrate
creates a `posts` table with id, title, body, created_at, and updated_at columns.
Ready to go further?

These free tutorials are a preview, our Backend Development cohort covers it in depth, with a real project and a cohort alongside you. Active

Enroll in Backend Development
Don't miss out

Ready to build something real?

Create a free account to enroll in a track, and get notified the moment a cohort opens.

Create free account