coolify/app/Models/Tag.php
Michael Jathe 23d5b854e9 feat(api): add tag management endpoints for applications, databases, and services
Add CRUD tag endpoints (GET/POST/DELETE) as sub-resources for applications,
databases, and services. Add team-level GET /tags endpoint. Extend all
resource creation endpoints to accept an optional tags array.

Uses a shared HandlesTagsApi trait to avoid duplication across controllers.
Tags are race-safe via syncWithoutDetaching(), garbage-collected when orphaned,
and sanitized (strip_tags + lowercase).
2026-03-29 16:02:05 +02:00

43 lines
981 B
PHP

<?php
namespace App\Models;
use App\Traits\HasSafeStringAttribute;
use OpenApi\Attributes as OA;
#[OA\Schema(
description: 'Tag model',
type: 'object',
properties: [
new OA\Property(property: 'uuid', type: 'string'),
new OA\Property(property: 'name', type: 'string'),
new OA\Property(property: 'created_at', type: 'string'),
new OA\Property(property: 'updated_at', type: 'string'),
]
)]
class Tag extends BaseModel
{
use HasSafeStringAttribute;
protected $guarded = [];
protected function customizeName($value)
{
return strtolower($value);
}
public static function ownedByCurrentTeam()
{
return Tag::whereTeamId(currentTeam()->id)->orderBy('name');
}
public function applications()
{
return $this->morphedByMany(Application::class, 'taggable');
}
public function services()
{
return $this->morphedByMany(Service::class, 'taggable');
}
}