41 lines
827 B
PHP
41 lines
827 B
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
|
|
class MobilModels extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $table = 'mobil';
|
|
|
|
protected $fillable = [
|
|
'nama_mobil',
|
|
'sub_kriteria_id',
|
|
'gambar',
|
|
'kelengkapan_mobil',
|
|
];
|
|
|
|
/**
|
|
* Relasi ke sub_kriteria (jenis mobil)
|
|
*/
|
|
public function subKriteria()
|
|
{
|
|
return $this->belongsTo(SubKriteriaModels::class, 'sub_kriteria_id');
|
|
}
|
|
|
|
/**
|
|
* Relasi ke nilai alternatif (one-to-many)
|
|
*/
|
|
public function nilaiAlternatifs()
|
|
{
|
|
return $this->hasMany(NilaiAlternatifModels::class);
|
|
}
|
|
public static function getMobilWithRelasi()
|
|
{
|
|
return self::with('subKriteria.kriteria')->get();
|
|
}
|
|
}
|