has_submodules = true; $parentModule->save(); } // insert module into database $module = Module::create([ 'name' => $name, 'description' => $description, 'handler' => $handler, 'manages_content' => $managesContent, 'support_categories' => $supportCategories, 'alias' => $alias, 'module_settings' => json_encode($settings), 'parent_id' => $parentModuleId ? $parentModuleId : null, 'enabled' => 1, 'is_template' => $isTemplate ]); // install something module-specific if ($handler) { call_user_func([$handler, 'install']); } return $module; } /** * Delete module from database and uninstall its dependencies * * @throws \ErrorException */ public function uninstall() { // check if user does not want to install module in runtime if (!App::runningInConsole()) { throw new \ErrorException('Modules can be uninstalled only via Artisan!'); } // delete everything in /resources/views/visitor $this->deleteDirectory(resource_path('views/visitor')); $this->deleteDirectory(public_path('assets')); $handler = $this->handler; if ($handler && is_callable([$handler, 'uninstall'])) { call_user_func([$handler, 'uninstall'], $this); } $this->delete(); } /** * Delete directory when uninstalling module. * * @param $directory * * @throws \ErrorException */ private function deleteDirectory($directory) { $success = \File::deleteDirectory($directory, true); if (!$success) { throw new \ErrorException('Cannot delete '.$directory); } } }