<?phpuse 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->string('title'); $table->text('body'); $table->boolean('published')->default(false); $table->timestamps(); }); } public function down(): void { Schema::dropIfExists('posts'); }};
<?phpuse 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'); $table->text('body'); $table->boolean('published')->default(false); $table->timestamp('published_at')->nullable(); $table->timestamps(); }); } public function down(): void { Schema::dropIfExists('posts'); }};
public function up(): void{ Schema::table('posts', function (Blueprint $table) { $table->string('excerpt')->nullable()->after('title'); });}public function down(): void{ Schema::table('posts', function (Blueprint $table) { $table->dropColumn('excerpt'); });}
use Illuminate\Database\Events\MigrationsEnded;use Illuminate\Support\Facades\Cache;use Illuminate\Support\Facades\Event;Event::listen(MigrationsEnded::class, function () { Cache::flush();});