get item relations
This commit is contained in:
@ -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 [];
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
@ -24,4 +24,9 @@ class TagEntity extends Model
|
||||
'entity_id' => 'Идентификатор сущности',
|
||||
];
|
||||
}
|
||||
|
||||
public function tag(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Tag::class);
|
||||
}
|
||||
}
|
@ -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){
|
||||
|
Reference in New Issue
Block a user