Skip to content

Commit

Permalink
REFACTOR: 🔨 Add return types and new relations for User and `Custom…
Browse files Browse the repository at this point in the history
…er` (#8)

* REFACTOR: 🔨 return types and new relations for User and Customer models

* CHORE: ⭐ sorting relations alphabetically
  • Loading branch information
khalidsheet authored Jan 26, 2024
1 parent a8f3484 commit ae3a845
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 29 deletions.
10 changes: 9 additions & 1 deletion app/Models/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,23 @@

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;


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);
}

}
3 changes: 2 additions & 1 deletion app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -44,7 +45,7 @@ class User extends Authenticatable
'password' => 'hashed',
];

public function customer()
public function customer(): BelongsTo
{
return $this->belongsTo(Customer::class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
27 changes: 0 additions & 27 deletions database/migrations/2024_01_26_092417_add_customer_id_to_users.php

This file was deleted.

0 comments on commit ae3a845

Please sign in to comment.