update, delete entity relations
This commit is contained in:
@ -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();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user