diff --git a/app/Models/Customer.php b/app/Models/Customer.php index 979a6e4..81f7a23 100644 --- a/app/Models/Customer.php +++ b/app/Models/Customer.php @@ -4,6 +4,7 @@ use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\SoftDeletes; @@ -11,8 +12,15 @@ class Customer extends Model { use HasFactory, SoftDeletes; - public function users() + + public function invoices(): HasMany + { + return $this->hasMany(Invoice::class); + } + + public function users(): HasMany { return $this->hasMany(User::class); } + } diff --git a/app/Models/User.php b/app/Models/User.php index 727bc94..d77bcc2 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -4,6 +4,7 @@ // use Illuminate\Contracts\Auth\MustVerifyEmail; use Illuminate\Database\Eloquent\Factories\HasFactory; +use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable; use Laravel\Sanctum\HasApiTokens; @@ -44,7 +45,7 @@ class User extends Authenticatable 'password' => 'hashed', ]; - public function customer() + public function customer(): BelongsTo { return $this->belongsTo(Customer::class); } diff --git a/database/migrations/2014_10_12_000000_create_users_table.php b/database/migrations/2014_10_12_000000_create_users_table.php index 95cbca9..ed428a2 100644 --- a/database/migrations/2014_10_12_000000_create_users_table.php +++ b/database/migrations/2014_10_12_000000_create_users_table.php @@ -12,6 +12,7 @@ public function up(): void { Schema::create('users', function (Blueprint $table) { $table->id(); + $table->foreignId('customer_id')->nullable(); $table->string('name'); $table->string('email')->unique(); $table->timestamp('email_verified_at')->nullable(); diff --git a/database/migrations/2024_01_26_092417_add_customer_id_to_users.php b/database/migrations/2024_01_26_092417_add_customer_id_to_users.php deleted file mode 100644 index 9b2f18b..0000000 --- a/database/migrations/2024_01_26_092417_add_customer_id_to_users.php +++ /dev/null @@ -1,27 +0,0 @@ -foreignId('customer_id')->after('id')->nullable(); - }); - } - - /** - * Reverse the migrations. - */ - public function down(): void - { - Schema::table('users', function (Blueprint $table) { - $table->dropConstrainedForeignId('customer_id'); - }); - } -};