2025_09_18_093938_create_badgeables_table.php 772B

1234567891011121314151617181920212223242526272829303132
  1. <?php
  2. use Illuminate\Database\Migrations\Migration;
  3. use Illuminate\Database\Schema\Blueprint;
  4. use Illuminate\Support\Facades\Schema;
  5. return new class extends Migration
  6. {
  7. /**
  8. * Run the migrations.
  9. */
  10. public function up(): void
  11. {
  12. Schema::create('badgeables', function (Blueprint $table) {
  13. $table->id();
  14. $table->foreignId('badge_id')->constrained()->cascadeOnDelete();
  15. $table->morphs('badgeable'); // 創建 taggable_id 和 taggable_type
  16. $table->timestamps();
  17. $table->unique(['badge_id', 'badgeable_id', 'badgeable_type']);
  18. });
  19. }
  20. /**
  21. * Reverse the migrations.
  22. */
  23. public function down(): void
  24. {
  25. Schema::dropIfExists('badgeables');
  26. }
  27. };