48 lines
1.2 KiB
PHP
48 lines
1.2 KiB
PHP
<?php
|
|
|
|
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;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
class Customer extends Model
|
|
{
|
|
use HasUuids, HasFactory, SoftDeletes;
|
|
|
|
protected $guarded = [];
|
|
|
|
protected $casts = [
|
|
'secondary_phones' => 'array',
|
|
'dob' => 'date',
|
|
'id_issue_date' => 'date',
|
|
];
|
|
|
|
/**
|
|
* Lấy các công ty mà 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')
|
|
->using(ContractCustomer::class)
|
|
->withPivot('id', 'role', 'transfer_order')
|
|
->withTimestamps();
|
|
}
|
|
}
|