From e0fe46deb900a3e53650a1c9bd01efcc570c2b29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=9A=A1Hamza=20=F0=9F=8C=A9=EF=B8=8F=20El=20Maghari=20?= =?UTF-8?q?=E2=9A=A1?= <84163115+hamzaelmaghari@users.noreply.github.com> Date: Sat, 16 Mar 2024 01:51:37 +0000 Subject: [PATCH] Update MakeSettingCommand.php Updated the getNamespace() method to check for and remove the leading backslash from the generated namespace and added a conditional check to remove the leading backslash if present in the namespace string. --- src/Console/MakeSettingCommand.php | 37 ++++++++++++++++++------------ 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/src/Console/MakeSettingCommand.php b/src/Console/MakeSettingCommand.php index ccde14f..0941429 100644 --- a/src/Console/MakeSettingCommand.php +++ b/src/Console/MakeSettingCommand.php @@ -108,20 +108,27 @@ protected function getPath($name, $path): string return $path . '/' . $name . '.php'; } - protected function getNamespace($path): string - { - $path = preg_replace( - [ - '/^(' . preg_quote(base_path(), '/') . ')/', - '/\//', - ], - [ - '', - '\\', - ], - $path - ); - - return implode('\\', array_map(fn ($directory) => ucfirst($directory), explode('\\', $path))); +protected function getNamespace($path): string +{ + $path = preg_replace( + [ + '/^(' . preg_quote(base_path(), '/') . ')/', + '/\//', + ], + [ + '', + '\\', + ], + $path + ); + + $namespace = implode('\\', array_map(fn ($directory) => ucfirst($directory), explode('\\', $path))); + + // Remove leading backslash if present + if (substr($namespace, 0, 1) === '\\') { + $namespace = substr($namespace, 1); } + + return $namespace; +} }