Skip to content

Commit 1bf3aaa

Browse files
authored
Fix: read app_folder variable from laravel-modules (#146)
Closing #127
2 parents 87104f6 + 90ca0f2 commit 1bf3aaa

File tree

4 files changed

+12
-8
lines changed

4 files changed

+12
-8
lines changed

src/Commands/ModuleMakeFilamentWidgetCommand.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ public function handle(): int
107107

108108
if (! $panel) {
109109
$namespace = $module->appNamespace('Livewire');
110-
$path = $module->appPath((string) str($namespace)->after('App\\')->replace('\\', '/'));
110+
$prefix = str(config('modules.paths.app_folder', 'app'))->ltrim(DIRECTORY_SEPARATOR, '\\')->studly();
111+
$path = $module->appPath((string) str($namespace)->after("{$prefix}\\")->replace('\\', '/'));
111112
} elseif ($resource === null) {
112113
$widgetDirectories = collect($panel->getWidgetDirectories())->filter(fn ($dir) => str($dir)->contains($module->appPath()))->values()->all();
113114
$widgetNamespaces = collect($panel->getWidgetNamespaces())->filter(fn ($dir) => str($dir)->contains($module->appNamespace()))->values()->all();

src/Concerns/GeneratesModularFiles.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ protected function rootNamespace(): string
4444

4545
protected function getPath($name): string
4646
{
47-
$name = Str::replaceFirst($this->rootNamespace(), 'app', $name);
47+
$appFolder = str(config('modules.paths.app_folder', 'app'));
48+
$name = Str::replaceFirst($this->rootNamespace(), $appFolder, $name);
4849

4950
return $this->getModule()->getExtraPath(str_replace('\\', DIRECTORY_SEPARATOR, $name) . '.php');
5051
}

src/ModulesPlugin.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,8 @@ protected function getModulePlugins(): array
8585
}
8686
// get a glob of all Filament plugins
8787
$basePath = str(config('modules.paths.modules', 'Modules'));
88-
$appFolder = trim(config('modules.paths.app_folder', 'app'), '/\\');
89-
$appPath = $appFolder . DIRECTORY_SEPARATOR;
90-
$pattern = $basePath . DIRECTORY_SEPARATOR . '*' . DIRECTORY_SEPARATOR . $appPath . 'Filament' . DIRECTORY_SEPARATOR . '*Plugin.php';
88+
$appFolder = str(config('modules.paths.app_folder', 'app'));
89+
$pattern = $basePath . DIRECTORY_SEPARATOR . '*' . DIRECTORY_SEPARATOR . $appFolder . DIRECTORY_SEPARATOR . 'Filament' . DIRECTORY_SEPARATOR . '*Plugin.php';
9190
$pluginPaths = glob($pattern);
9291

9392
return collect($pluginPaths)->map(fn ($path) => FilamentModules::convertPathToNamespace($path))->toArray();
@@ -103,7 +102,8 @@ protected function getModulePanels(): array
103102
{
104103
// get a glob of all Filament panels
105104
$basePath = str(config('modules.paths.modules', 'Modules'));
106-
$pattern = $basePath . DIRECTORY_SEPARATOR . '*' . DIRECTORY_SEPARATOR . 'app' . DIRECTORY_SEPARATOR . 'Providers' . DIRECTORY_SEPARATOR . 'Filament' . DIRECTORY_SEPARATOR . '*.php';
105+
$appFolder = str(config('modules.paths.app_folder', 'app'));
106+
$pattern = $basePath . DIRECTORY_SEPARATOR . '*' . DIRECTORY_SEPARATOR . $appFolder . DIRECTORY_SEPARATOR . 'Providers' . DIRECTORY_SEPARATOR . 'Filament' . DIRECTORY_SEPARATOR . '*.php';
107107
$panelPaths = glob($pattern);
108108

109109
$panelIds = collect($panelPaths)->map(fn ($path) => FilamentModules::convertPathToNamespace($path))->map(function ($class) {

src/ModulesServiceProvider.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,10 @@ protected function registerModuleMacros(): void
222222
Module::macro('appNamespace', function (string $relativeNamespace = '') {
223223
$prefix = str(config('modules.paths.app_folder', 'app'))->ltrim(DIRECTORY_SEPARATOR, '\\')->studly();
224224
$relativeNamespace = trim($relativeNamespace, '\\');
225-
$relativeNamespace = str_replace($prefix . '\\', '', $relativeNamespace);
226-
$relativeNamespace = str_replace($prefix, '', $relativeNamespace);
225+
if ($prefix != '') {
226+
$relativeNamespace = str_replace($prefix . '\\', '', $relativeNamespace);
227+
$relativeNamespace = str_replace($prefix, '', $relativeNamespace);
228+
}
227229
$relativeNamespace = trim($relativeNamespace, '\\');
228230
$relativeNamespace = '\\' . $relativeNamespace;
229231

0 commit comments

Comments
 (0)