Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

2023_09_19_050544_create_contacts_table.php 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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('contacts', function (Blueprint $table) {
  13. $table->id();
  14. $table->foreignId('company_id')->constrained()->cascadeOnDelete();
  15. $table->string('type')->nullable();
  16. $table->string('name');
  17. $table->string('email');
  18. $table->string('address', 255)->nullable();
  19. $table->unsignedMediumInteger('city_id')->nullable()->index();
  20. $table->string('zip_code', 20)->nullable();
  21. $table->unsignedSmallInteger('state_id')->nullable()->index();
  22. $table->string('country')->nullable();
  23. $table->string('timezone')->nullable();
  24. $table->string('language')->nullable();
  25. $table->string('contact_method')->nullable();
  26. $table->string('phone_number', 30)->nullable();
  27. $table->string('tax_id', 50)->nullable();
  28. $table->string('currency_code', 10);
  29. $table->string('website', 255)->nullable();
  30. $table->string('reference', 255)->nullable();
  31. $table->foreignId('created_by')->nullable()->constrained('users')->nullOnDelete();
  32. $table->foreignId('updated_by')->nullable()->constrained('users')->nullOnDelete();
  33. $table->timestamps();
  34. $table->index(['company_id', 'type']);
  35. $table->unique(['company_id', 'type', 'email']);
  36. $table->foreign(['company_id', 'currency_code'])
  37. ->references(['company_id', 'code'])
  38. ->on('currencies')
  39. ->restrictOnDelete();
  40. });
  41. }
  42. /**
  43. * Reverse the migrations.
  44. */
  45. public function down(): void
  46. {
  47. Schema::dropIfExists('contacts');
  48. }
  49. };