Kimi chinh sua

This commit is contained in:
2026-04-24 08:58:53 +00:00
parent 91ff4a5e4d
commit 86216ef872
43 changed files with 2868 additions and 597 deletions

View File

@@ -5,6 +5,8 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Concerns\HasUuids;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
class Customer extends Model
{
@@ -12,12 +14,28 @@ class Customer extends Model
protected $guarded = [];
// Ép kiểu để Laravel tự động dịch JSON thành Mảng khi hiển thị lên Form
protected $casts = [
'address' => 'array',
'secondary_phones' => 'array',
'dob' => 'date',
'id_issue_date' => 'date',
];
/**
* Lấy các công ty khách hàng này đại diện
*/
public function representedCompanies(): HasMany
{
return $this->hasMany(Customer::class, 'representative_id');
}
/**
* Lấy người đại diện của công ty này
*/
public function representative(): BelongsTo
{
return $this->belongsTo(Customer::class, 'representative_id');
}
public function contracts()
{
return $this->belongsToMany(Contract::class, 'contract_customers')
@@ -25,4 +43,4 @@ class Customer extends Model
->withPivot('id', 'role', 'transfer_order')
->withTimestamps();
}
}
}