forked from admin/services_core
99 lines
2.1 KiB
PHP
99 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
class Customer extends Model
|
|
{
|
|
use SoftDeletes;
|
|
|
|
protected $guarded = ['id'];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'latitude' => 'decimal:7',
|
|
'longitude' => 'decimal:7',
|
|
'activated_at' => 'datetime',
|
|
'inactivated_at' => 'datetime',
|
|
];
|
|
}
|
|
|
|
public function tenant()
|
|
{
|
|
return $this->belongsTo(Tenant::class);
|
|
}
|
|
|
|
public function user()
|
|
{
|
|
return $this->belongsTo(User::class);
|
|
}
|
|
|
|
public function provinsi()
|
|
{
|
|
return $this->belongsTo(WilayahProvinsi::class, 'provinsi_id');
|
|
}
|
|
|
|
public function kabupaten()
|
|
{
|
|
return $this->belongsTo(WilayahKabupaten::class, 'kabupaten_id');
|
|
}
|
|
|
|
public function kecamatan()
|
|
{
|
|
return $this->belongsTo(WilayahKecamatan::class, 'kecamatan_id');
|
|
}
|
|
|
|
public function desa()
|
|
{
|
|
return $this->belongsTo(WilayahDesa::class, 'desa_id');
|
|
}
|
|
|
|
public function packageProfile()
|
|
{
|
|
return $this->belongsTo(NasPackageProfile::class, 'package_profile_id');
|
|
}
|
|
|
|
public function nasMikrotik()
|
|
{
|
|
return $this->belongsTo(NasMikrotik::class, 'nas_mikrotik_id');
|
|
}
|
|
|
|
public function images()
|
|
{
|
|
return $this->hasMany(CustomerImage::class)->orderByDesc('is_cover')->orderBy('sort_order');
|
|
}
|
|
|
|
public function coverImage()
|
|
{
|
|
return $this->hasOne(CustomerImage::class)->where('is_cover', true);
|
|
}
|
|
|
|
public function billingProfile()
|
|
{
|
|
return $this->belongsTo(BillingProfile::class);
|
|
}
|
|
|
|
public function invoices()
|
|
{
|
|
return $this->hasMany(Invoice::class);
|
|
}
|
|
|
|
public function topologyConnections()
|
|
{
|
|
return $this->hasMany(TopologyCustomerConnection::class);
|
|
}
|
|
|
|
public function activeTopologyConnection()
|
|
{
|
|
return $this->hasOne(TopologyCustomerConnection::class)->where('status', 'active');
|
|
}
|
|
|
|
public function contacts()
|
|
{
|
|
return $this->hasMany(CustomerContact::class);
|
|
}
|
|
}
|