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

@ -185,4 +185,19 @@ class EntityRelation
}
}
}
public function getEntityAdditionalProperty(string $entity, Model $model): array
{
$relations = $this->getEntityRelationsBySlug($entity);
if ($relations){
foreach ($relations as $relation){
$moduleClass = $this->getAdditionalPropertyClassBySlug($relation);
if ($moduleClass and method_exists($moduleClass, "getItems")) {
return $moduleClass->getItems($entity, $model);
}
}
}
return [];
}
}

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);
}
}

View File

@ -25,6 +25,9 @@ $table->beforePrint(function () use ($content) {
return $btn;
});
$entityRelation = new \kernel\EntityRelation();
$additional = $entityRelation->getEntityAdditionalProperty("post", $content);
$table->rows([
'created_at' => function ($data) {
if (!$data){