Vulnerability.php
1 <?php 2 3 namespace App\Models; 4 5 use Illuminate\Database\Eloquent\Factories\HasFactory; 6 use Illuminate\Database\Eloquent\Model; 7 use Illuminate\Database\Eloquent\Relations\BelongsToMany; 8 use Illuminate\Database\Eloquent\Relations\Pivot; 9 10 class Vulnerability extends Model 11 { 12 use HasFactory; 13 14 protected $fillable = [ 15 'artifact_name', 16 'artifact_version', 17 'artifact_type', 18 'vid', 19 'severity', 20 'description', 21 'state', 22 'source', 23 ]; 24 25 public function toes(): BelongsToMany 26 { 27 return $this->belongsToMany(TOE::class, 'toe_vulnerability', 'vulnerability_id', 'toe_id') 28 ->withPivot('applies', 'rationale', 'reviewed_at', 'reviewed_by'); 29 } 30 31 public function getToeVulnerability(int $toeId): Pivot 32 { 33 return $this->toes()->find($toeId)->pivot; 34 } 35 }