49 lines
1.1 KiB
PHP
49 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class Alternatif extends Model
|
|
{
|
|
use HasFactory;
|
|
protected $table = 'tbl_data_alternatif';
|
|
protected $primaryKey = 'id_alternatif';
|
|
protected $fillable = [
|
|
'id_alternatif',
|
|
'nama_alternatif',
|
|
'uplink',
|
|
'created_at',
|
|
'updated_at'
|
|
];
|
|
|
|
public $timestamps = false;
|
|
public $keyType = 'string';
|
|
|
|
public function skorPreferensi()
|
|
{
|
|
return $this->hasOne(PengajuanNasabah::class, 'id_pengajuan', 'id_alternatif');
|
|
}
|
|
|
|
public function agen()
|
|
{
|
|
return $this->hasOne(User::class, 'id', 'uplink');
|
|
}
|
|
|
|
public function nilai()
|
|
{
|
|
return $this->hasOne(Nilai::class, 'alternatif_kode', 'id_alternatif');
|
|
}
|
|
|
|
protected static function boot()
|
|
{
|
|
parent::boot();
|
|
|
|
static::deleting(function ($alternatif) {
|
|
// Hapus semua nilai yang memiliki alternatif_kode sama dengan id_alternatif yang akan dihapus
|
|
$alternatif->nilai()->delete();
|
|
});
|
|
}
|
|
}
|