2025_04_03_192940_create_responsibles_table.php 1.1 KB

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