get item relations

This commit is contained in:
2024-11-27 17:11:06 +03:00
parent bba35c7b14
commit 2133fae2cc
5 changed files with 58 additions and 16 deletions

View File

@ -42,4 +42,20 @@ class Tag extends Model
];
}
public static function getTagListByEntity(string $entity): array
{
return self::where("entity", $entity)->get()->toArray();
}
public static function getTagLabelByEntity(string $entity): array
{
$result = [];
$tags = self::getTagListByEntity($entity);
foreach ($tags as $tag){
$result[$tag['id']] = $tag['label'];
}
return $result;
}
}

View File

@ -24,4 +24,9 @@ class TagEntity extends Model
'entity_id' => 'Идентификатор сущности',
];
}
public function tag(): \Illuminate\Database\Eloquent\Relations\BelongsTo
{
return $this->belongsTo(Tag::class);
}
}