<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration // --------------------------- 直接 return 匿名类
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('flights', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('airline');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('flights');
}
};
为什么会迁移的时候会多出文件?
php artisan migrate
不是只会运行database/migrations
中的迁移文件吗?对于重复的类名。在最新的 Laravel 9.x 中使用匿名类来解决这个问题
source: https://laravel.com/docs/9.x/...