Kimi chinh sua
This commit is contained in:
@@ -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 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')
|
||||
@@ -25,4 +43,4 @@ class Customer extends Model
|
||||
->withPivot('id', 'role', 'transfer_order')
|
||||
->withTimestamps();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user