الخطوة الأولى، إنشاء ملف الـ migration:
php artisan make:migration create_posts_table
ثم تعريف الأعمدة في الملف الناتج داخل database/migrations:
public function up(): void
{
Schema::create('posts', function (Blueprint $table) {
$table->id();
$table->string('title');
$table->text('body');
$table->timestamps();
});
}
وأخيرًا التنفيذ:
php artisan migrate
اختصار مفيد
php artisan make:model Post -m # model + migration together
ميزة الـ migrations أن بنية قاعدة البيانات محفوظة في الكود، فيمكن إعادة بنائها على أي جهاز بأمر واحد.