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.
// 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
creates a `posts` table with id, title, body, created_at, and updated_at columns.