2024-02-01 14:38:12 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
2025-08-19 10:14:48 +00:00
|
|
|
use App\Traits\HasSafeStringAttribute;
|
2026-07-07 11:56:33 +00:00
|
|
|
use Illuminate\Support\Facades\DB;
|
2026-03-29 14:02:05 +00:00
|
|
|
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
|
|
|
|
|
{
|
2025-08-19 10:14:48 +00:00
|
|
|
use HasSafeStringAttribute;
|
2025-08-19 09:04:23 +00:00
|
|
|
|
2026-03-29 19:25:41 +00:00
|
|
|
protected $fillable = [
|
|
|
|
|
'name',
|
2026-03-31 11:45:31 +00:00
|
|
|
'team_id',
|
2026-03-29 19:25:41 +00:00
|
|
|
];
|
2024-02-01 14:38:12 +00:00
|
|
|
|
2025-08-19 10:14:48 +00:00
|
|
|
protected function customizeName($value)
|
2024-02-01 14:38:12 +00:00
|
|
|
{
|
2025-08-19 10:14:48 +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
|
|
|
|
2026-07-07 11:56:33 +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
|
|
|
}
|
|
|
|
|
}
|