Files
coolify/app/Traits/HasImageScans.php
033f0c84da v4.7 (#12478)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: peaklabs-dev <122374094+peaklabs-dev@users.noreply.github.com>
Co-authored-by: Aditya Tripathi <aditya@climactic.co>
2026-11-06 14:25:02 +01:00

35 lines
1.1 KiB
PHP

<?php
namespace App\Traits;
use App\Models\ImageScan;
use App\Models\ImageScanIgnore;
use App\Models\ImageScanNotificationState;
use App\Models\ImageScanPolicy;
use Illuminate\Database\Eloquent\Relations\MorphMany;
/**
* Vulnerability scans of the images a resource runs. The scans, the scan rules, the ignores, and the notification
* state of the resource go away with it.
*/
trait HasImageScans
{
public static function bootHasImageScans(): void
{
static::deleting(function ($model): void {
$model->imageScans()->delete();
ImageScanPolicy::query()->where('scope_type', $model->getMorphClass())->where('scope_id', $model->getKey())->delete();
ImageScanIgnore::query()->where('resource_type', $model->getMorphClass())->where('resource_id', $model->getKey())->delete();
ImageScanNotificationState::query()->where('resource_type', $model->getMorphClass())->where('resource_id', $model->getKey())->delete();
});
}
/**
* @return MorphMany<ImageScan, $this>
*/
public function imageScans(): MorphMany
{
return $this->morphMany(ImageScan::class, 'resource');
}
}