Skip to content

Commit eabc1e6

Browse files
committed
Bug Fix: Wrong Path appFilament when generating resources with the default config
1 parent bccac96 commit eabc1e6

File tree

3 files changed

+17
-15
lines changed

3 files changed

+17
-15
lines changed

src/Commands/ModuleMakeFilamentPluginCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function handle(): ?bool
4444
{
4545
$this->ensureModule();
4646

47-
return parent::handle(); // TODO: Change the autogenerated stub
47+
return parent::handle();
4848
}
4949

5050
public function ensureModule()

src/Concerns/GeneratesModularFiles.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,17 @@ protected function rootNamespace(): string
4545
protected function getPath($name): string
4646
{
4747
$appFolder = trim(config('modules.paths.app_folder', 'app/'), '/\\');
48-
$name = Str::replaceFirst($this->rootNamespace(), $appFolder, $name);
49-
48+
$rootNamespace = str($this->rootNamespace())->trim('\\')->toString();
49+
$name = Str::replaceFirst($rootNamespace, $appFolder, $name);
5050
return $this->getModule()->getExtraPath(str_replace('\\', DIRECTORY_SEPARATOR, $name) . '.php');
5151
}
5252

5353
protected function possibleModels()
5454
{
55-
$modelPath = $this->getModule()->appPath(config('modules.paths.generator.model.path', 'Models'));
56-
55+
$appFolder =trim(config('modules.paths.app_folder', 'app/'), '/\\');
56+
$modelPath = str(config('modules.paths.model_folder', 'app/Models'))
57+
->replaceFirst($appFolder, '')->replace(DIRECTORY_SEPARATOR.DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR)->trim(DIRECTORY_SEPARATOR)->toString();
58+
$modelPath = $this->getModule()->appPath($modelPath);
5759
return collect(Finder::create()->files()->depth(0)->in($modelPath))
5860
->map(fn ($file) => $file->getBasename('.php'))
5961
->sort()

src/ModulesServiceProvider.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ public function attemptToRegisterModuleProviders(): void
7575
) . '/*' . DIRECTORY_SEPARATOR . '*' . DIRECTORY_SEPARATOR . 'Providers' . DIRECTORY_SEPARATOR . 'Filament' . DIRECTORY_SEPARATOR . '*Provider.php';
7676
$serviceProviders = glob($pattern1);
7777
$panelProviders = glob($pattern2);
78-
// dd($panelProviders);
7978
$providers = array_merge($serviceProviders, $panelProviders);
8079

8180
foreach ($providers as $provider) {
@@ -207,13 +206,12 @@ protected function getMigrations(): array
207206

208207
protected function registerModuleMacros(): void
209208
{
210-
Module::macro('namespace', function (string $relativeNamespace = '') {
209+
Module::macro('namespace', function (?string $relativeNamespace = '') {
210+
$relativeNamespace = $relativeNamespace ?? '';
211211
$base = trim($this->app['config']->get('modules.namespace', 'Modules'), '\\');
212212
$relativeNamespace = trim($relativeNamespace, '\\');
213213
$studlyName = $this->getStudlyName();
214-
215214
return str($base)->append('\\')->append($studlyName)->append('\\')->append($relativeNamespace)->replace('\\\\', '\\')->toString();
216-
// return trim("{$base}\\{$studlyName}\\{$relativeNamespace}", '\\');
217215
});
218216

219217
Module::macro('getTitle', function () {
@@ -233,37 +231,39 @@ protected function registerModuleMacros(): void
233231
Module::macro('appPath', function (string $relativePath = '') {
234232
$appPath = $this->getExtraPath(config('modules.paths.app_folder', 'app'));
235233

236-
return $appPath . ($relativePath ? DIRECTORY_SEPARATOR . $relativePath : '');
234+
return str($appPath . ($relativePath ? DIRECTORY_SEPARATOR . $relativePath : ''))->replace(DIRECTORY_SEPARATOR.DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR)->toString();
237235
});
238236

239237
Module::macro('databasePath', function (string $relativePath = '') {
240238
$appPath = $this->getExtraPath('database');
241239

242-
return $appPath . ($relativePath ? DIRECTORY_SEPARATOR . $relativePath : '');
240+
return str($appPath . ($relativePath ? DIRECTORY_SEPARATOR . $relativePath : ''))->replace(DIRECTORY_SEPARATOR.DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR)->toString();
243241
});
244242

245243
Module::macro('resourcesPath', function (string $relativePath = '') {
246244
$appPath = $this->getExtraPath('resources');
247245

248-
return $appPath . ($relativePath ? DIRECTORY_SEPARATOR . $relativePath : '');
246+
return str($appPath . ($relativePath ? DIRECTORY_SEPARATOR . $relativePath : ''))
247+
->replace(DIRECTORY_SEPARATOR.DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR)->toString();
249248
});
250249

251250
Module::macro('migrationsPath', function (string $relativePath = '') {
252251
$appPath = $this->databasePath('migrations');
253252

254-
return $appPath . ($relativePath ? DIRECTORY_SEPARATOR . $relativePath : '');
253+
return str($appPath . ($relativePath ? DIRECTORY_SEPARATOR . $relativePath : ''))
254+
->replace(DIRECTORY_SEPARATOR.DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR)->toString();
255255
});
256256

257257
Module::macro('seedersPath', function (string $relativePath = '') {
258258
$appPath = $this->databasePath('seeders');
259259

260-
return $appPath . ($relativePath ? DIRECTORY_SEPARATOR . $relativePath : '');
260+
return str($appPath . ($relativePath ? DIRECTORY_SEPARATOR . $relativePath : ''))->replace(DIRECTORY_SEPARATOR.DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR)->toString();
261261
});
262262

263263
Module::macro('factoriesPath', function (string $relativePath = '') {
264264
$appPath = $this->databasePath('factories');
265265

266-
return $appPath . ($relativePath ? DIRECTORY_SEPARATOR . $relativePath : '');
266+
return str($appPath . ($relativePath ? DIRECTORY_SEPARATOR . $relativePath : ''))->replace(DIRECTORY_SEPARATOR.DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR)->toString();
267267
});
268268
}
269269
}

0 commit comments

Comments
 (0)