coolify/app/Models/Tag.php

55 lines
1.2 KiB
PHP
Raw Permalink Normal View History

2024-02-01 14:38:12 +00:00
<?php
namespace App\Models;
use App\Traits\HasSafeStringAttribute;
use Illuminate\Support\Facades\DB;
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'),
]
)]
2024-02-01 14:38:12 +00:00
class Tag extends BaseModel
{
use HasSafeStringAttribute;
protected $fillable = [
'name',
'team_id',
];
2024-02-01 14:38:12 +00:00
protected function customizeName($value)
2024-02-01 14:38:12 +00:00
{
return strtolower($value);
2024-02-01 14:38:12 +00:00
}
2024-06-10 20:43:34 +00:00
public static function ownedByCurrentTeam()
2024-02-01 14:38:12 +00:00
{
return Tag::whereTeamId(currentTeam()->id)->orderBy('name');
}
2024-06-10 20:43:34 +00:00
public function deleteIfOrphaned(): void
{
if (DB::table('taggables')->where('tag_id', $this->id)->doesntExist()) {
$this->delete();
}
}
2024-02-01 14:38:12 +00:00
public function applications()
{
return $this->morphedByMany(Application::class, 'taggable');
}
2024-06-10 20:43:34 +00:00
2024-02-03 11:39:07 +00:00
public function services()
{
return $this->morphedByMany(Service::class, 'taggable');
2024-02-01 14:38:12 +00:00
}
}