2025_04_03_192940_create_responsibles_table.php 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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('responsibles', function (Blueprint $table) {
  13. $table->id();
  14. $table->string('name');
  15. $table->string('phone');
  16. $table->timestamps();
  17. });
  18. Schema::table('areas', function (Blueprint $table) {
  19. $table->foreignId('responsible_id')
  20. ->nullable()
  21. ->after('district_id')
  22. ->constrained('responsibles')
  23. ->nullOnDelete();
  24. });
  25. }
  26. /**
  27. * Reverse the migrations.
  28. */
  29. public function down(): void
  30. {
  31. Schema::table('areas', function (Blueprint $table) {
  32. $table->dropForeign('areas_responsible_id_foreign');
  33. $table->dropColumn('responsible_id');
  34. });
  35. Schema::dropIfExists('responsibles');
  36. }
  37. };