113 lines
2.9 KiB
PHP
113 lines
2.9 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Http\Controllers\PelaporanController;
|
|
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 Perusahaan extends Model
|
|
{
|
|
use HasFactory;
|
|
protected $table = 'Perusahaan';
|
|
protected $primaryKey = 'PerusahaanId';
|
|
|
|
|
|
protected $fillable = [
|
|
'NomorInduk',
|
|
'JenisKegiatanId',
|
|
'NamaPerusahaan',
|
|
'Alamat',
|
|
'KelurahanId',
|
|
'KodePos',
|
|
'Telepon',
|
|
'Fax',
|
|
'Email',
|
|
'Lintang',
|
|
'Bujur',
|
|
'CPNama',
|
|
'CPTelepon',
|
|
'ILNomor',
|
|
'ILTanggal',
|
|
'JenisDokILId',
|
|
'VerifikatorId',
|
|
'IsPublish',
|
|
'ILDokumen',
|
|
'ReportLocked'
|
|
];
|
|
|
|
protected $casts = [
|
|
'ReportLocked' => 'boolean',
|
|
'IsPublish' => 'boolean',
|
|
'JenisKegiatanId' => 'integer',
|
|
'VerifikatorId' => 'integer',
|
|
'KelurahanId' => 'integer',
|
|
];
|
|
|
|
public function jenisKegiatan()
|
|
{
|
|
return $this->belongsTo(JenisKegiatan::class, 'JenisKegiatanId', 'JenisKegiatanId');
|
|
}
|
|
|
|
protected $with = ['JenisKegiatan', 'Kelurahan'];
|
|
|
|
public function kelurahan()
|
|
{
|
|
return $this->belongsTo(Kelurahan::class, 'KelurahanId', 'KelurahanId');
|
|
}
|
|
|
|
|
|
public function kecamatan()
|
|
{
|
|
return $this->hasOneThrough(
|
|
Kecamatan::class,
|
|
Kelurahan::class,
|
|
'KelurahanId', // Foreign key di tabel Kelurahan
|
|
'KecamatanId', // Foreign key di tabel Kecamatan
|
|
'KelurahanId', // Foreign key di tabel Perusahaan
|
|
'KecamatanId' // Foreign key di tabel Kelurahan
|
|
);
|
|
}
|
|
|
|
public function kabupaten()
|
|
{
|
|
return $this->hasOneThrough(
|
|
Kabupaten::class,
|
|
Kecamatan::class,
|
|
'KecamatanId', // Foreign key di tabel Kecamatan
|
|
'KabupatenId', // Foreign key di tabel Kabupaten
|
|
'KelurahanId', // Foreign key di tabel Perusahaan
|
|
'KabupatenId' // Foreign key di tabel Kecamatan
|
|
);
|
|
}
|
|
|
|
public function verifikator()
|
|
{
|
|
return $this->belongsTo(Verifikator::class, 'VerifikatorId');
|
|
}
|
|
// Relationship with JenisDokIL
|
|
public function jenisDokIL()
|
|
{
|
|
return $this->belongsTo(JenisDokIL::class, 'JenisDokILId', 'JenisDokILId');
|
|
}
|
|
|
|
public function refhistoryKegiatan()
|
|
{
|
|
return $this->belongsTo(RefHistoryKegiatan::class, 'RefHistoryKegiatanId', 'RefHistoryKegiatanId');
|
|
}
|
|
|
|
|
|
public function historyPerusahaan(): HasMany
|
|
{
|
|
return $this->hasMany(HistoryPerusahaan::class, 'PerusahaanId', 'PerusahaanId');
|
|
}
|
|
|
|
public function pelaporan()
|
|
{
|
|
return $this->belongsTo(PelaporanController::class, 'PelaporanId', 'PelaporanId');
|
|
}
|
|
}
|