update, delete entity relations

This commit is contained in:
2024-11-28 15:34:57 +03:00
parent 44e61a2030
commit 921569b950
4 changed files with 45 additions and 5 deletions

View File

@ -61,10 +61,19 @@ class TagModule extends Module
public function formInputs(string $entity, Model $model = null): void
{
if (isset($model)) {
$tags= TagEntity::where("entity_id", $model->id)->get()->toArray();
$value = [];
foreach ($tags as $tag) {
$val = Tag::where('id', $tag['tag_id'])->first()->toArray();
$value[] = $val['label'];
}
}
$input = SelectBuilder::build("tag[]", [
'class' => 'form-control',
'placeholder' => 'Теги',
'value' => '',
'value' => $value ?? '',
'multiple' => "multiple",
'options' => Tag::getTagLabelByEntity($entity)
]);
@ -97,4 +106,9 @@ class TagModule extends Module
return substr($tagsStr, 0, -2);
}
public function deleteItems(string $entity, Model $model): void
{
TagEntity::where("entity", $entity)->where("entity_id", $model->id)->delete();
}
}