add and remove entity relations
This commit is contained in:
@ -53,9 +53,22 @@ class EntityRelation
|
||||
return false;
|
||||
}
|
||||
|
||||
public function removeFromEntityRelations(string $entity, string $property)
|
||||
public function removeFromEntityRelations(string $entity, string $property): bool
|
||||
{
|
||||
$entity_relations_info = Option::where("key", "entity_relations")->first();
|
||||
if ($entity_relations_info) {
|
||||
$entity_relations = json_decode($entity_relations_info->value, true);
|
||||
if ($entity_relations[$entity]) {
|
||||
if ($entity_relations[$entity][$property]) {
|
||||
unset($entity_relations[$entity][$property]);
|
||||
$entity_relations_info->value = json_encode($entity_relations, JSON_UNESCAPED_UNICODE);
|
||||
$entity_relations_info->save();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getEntityRelationsBySlug(string $slug)
|
||||
@ -70,14 +83,15 @@ class EntityRelation
|
||||
return false;
|
||||
}
|
||||
|
||||
public function addEntityRelation(array $data): bool
|
||||
public function addEntityRelation(string $entity, string $property): bool
|
||||
{
|
||||
$entity_relations_info = Option::where("key", "entity_relations")->first();
|
||||
|
||||
if ($entity_relations_info) {
|
||||
$entity_relations = json_decode($entity_relations_info->value, true);
|
||||
foreach ($data as $entity => $relation) {
|
||||
$entity_relations[$entity] = $relation;
|
||||
if (isset($entity_relations[$entity])) {
|
||||
$entity_relations[$entity][] = $property;
|
||||
} else {
|
||||
$entity_relations[$entity] = $property;
|
||||
}
|
||||
$entity_relations_info->value = json_encode($entity_relations, JSON_UNESCAPED_UNICODE);
|
||||
$entity_relations_info->save();
|
||||
|
Reference in New Issue
Block a user