twigRepository = $twigRepository; $this->templateQuery = $templateQuery; } /** * @param Twig $twig [description] * * @return bool [description] */ public function delete(Twig $twig): bool { $this->deleteTemplatesAndProjectsImpact($twig); return $this->twigRepository->delete($twig); } /** * This will delete each twig's template manually without use realtion cause we need to delete related template's data in project * * @param Twig $twig * * @return void */ private function deleteTemplatesAndProjectsImpact(Twig $twig): void { $templates = $twig->getTemplates(); foreach ($templates as $template) { if (!$template->getDeletedAt()) { $this->templateQuery->delete($template); } } } }