diff --git a/app/Library/Structures/StructureHelper.php b/app/Library/Structures/StructureHelper.php index 44e414094..3e1bbf26e 100644 --- a/app/Library/Structures/StructureHelper.php +++ b/app/Library/Structures/StructureHelper.php @@ -262,7 +262,10 @@ class StructureHelper { //Update the services for the structure as well if($services == true) { //Delete the existing services, then add the new services - Service::where(['structure_id' => $structure->structure_id, ])->delete(); + if(Service::where(['structure_id' => $structure->structure_id])->count() > 0) { + Service::where(['structure_id' => $structure->structure_id])->delete(); + } + foreach($structure->services as $service) { $serv = new Service; @@ -340,7 +343,7 @@ class StructureHelper { if($st->services == true) { foreach($structure->services as $service) { $serv = new Service; - $serv->sructure_id = $structure->structure_id; + $serv->structure_id = $structure->structure_id; $serv->name = $service->name; $serv->state = $service->state; }