Merge pull request #17207 from steelvirus/4.x

[4.x] Use laravel provided namespace
This commit is contained in:
Dan Harrin
2025-08-08 13:27:39 +01:00
committed by GitHub
37 changed files with 141 additions and 137 deletions
@@ -32,12 +32,12 @@ class AdminPanelProvider extends PanelProvider
->colors([
'primary' => Color::Amber,
])
->discoverResources(in: app_path('Filament/Resources'), for: 'App\\Filament\\Resources')
->discoverPages(in: app_path('Filament/Pages'), for: 'App\\Filament\\Pages')
->discoverResources(in: app_path('Filament/Resources'), for: app()->getNamespace() . 'Filament\\Resources')
->discoverPages(in: app_path('Filament/Pages'), for: app()->getNamespace() . 'Filament\\Pages')
->pages([
Pages\Dashboard::class,
])
->discoverWidgets(in: app_path('Filament/Widgets'), for: 'App\\Filament\\Widgets')
->discoverWidgets(in: app_path('Filament/Widgets'), for: app()->getNamespace() . 'Filament\\Widgets')
->widgets([
Widgets\AccountWidget::class,
Widgets\FilamentInfoWidget::class,
@@ -84,7 +84,7 @@ class MakeExporterCommand extends Command
name: 'model-namespace',
shortcut: null,
mode: InputOption::VALUE_REQUIRED,
description: 'The namespace of the model class, [App\\Models] by default',
description: 'The namespace of the model class, [' . app()->getNamespace() . 'Models] by default',
),
new InputOption(
name: 'force',
@@ -131,7 +131,7 @@ class MakeExporterCommand extends Command
$this->modelFqnEnd = 'Resource';
}
$modelNamespace = $this->option('model-namespace') ?? 'App\\Models';
$modelNamespace = $this->option('model-namespace') ?? app()->getNamespace() . 'Models';
$this->modelFqn = "{$modelNamespace}\\{$this->modelFqnEnd}";
} else {
@@ -151,7 +151,7 @@ class MakeExporterCommand extends Command
fn (string $class): bool => str($class)->replace(['\\', '/'], '')->contains($search, ignoreCase: true),
);
},
placeholder: 'App\\Models\\BlogPost',
placeholder: app()->getNamespace() . 'Models\\BlogPost',
required: true,
);
@@ -90,7 +90,7 @@ class MakeImporterCommand extends Command
name: 'model-namespace',
shortcut: null,
mode: InputOption::VALUE_REQUIRED,
description: 'The namespace of the model class, [App\\Models] by default',
description: 'The namespace of the model class, [' . app()->getNamespace() . 'Models] by default',
),
new InputOption(
name: 'force',
@@ -138,7 +138,7 @@ class MakeImporterCommand extends Command
$this->modelFqnEnd = 'Resource';
}
$modelNamespace = $this->option('model-namespace') ?? 'App\\Models';
$modelNamespace = $this->option('model-namespace') ?? app()->getNamespace() . 'Models';
$this->modelFqn = "{$modelNamespace}\\{$this->modelFqnEnd}";
} else {
@@ -158,7 +158,7 @@ class MakeImporterCommand extends Command
fn (string $class): bool => str($class)->replace(['\\', '/'], '')->contains($search, ignoreCase: true),
);
},
placeholder: 'App\\Models\\BlogPost',
placeholder: app()->getNamespace() . 'Models\\BlogPost',
required: true,
);
+1 -1
View File
@@ -77,7 +77,7 @@ abstract class Exporter
{
return static::$model ?? (string) str(class_basename(static::class))
->beforeLast('Exporter')
->prepend('App\\Models\\');
->prepend(app()->getNamespace() . 'Models\\');
}
abstract public static function getCompletedNotificationBody(Export $export): string;
@@ -2,7 +2,6 @@
namespace Filament\Actions\Exports\Models;
use App\Models\User;
use Carbon\CarbonInterface;
use Exception;
use Filament\Actions\Exports\Exporter;
@@ -58,12 +57,14 @@ class Export extends Model
return $this->belongsTo($authenticatable::class);
}
if (! class_exists(User::class)) {
throw new Exception('No [App\\Models\\User] model found. Please bind an authenticatable model to the [Illuminate\\Contracts\\Auth\\Authenticatable] interface in a service provider\'s [register()] method.');
$userClass = app()->getNamespace() . 'Models\\User';
if (! class_exists($userClass)) {
throw new Exception('No [' . $userClass . '] model found. Please bind an authenticatable model to the [Illuminate\\Contracts\\Auth\\Authenticatable] interface in a service provider\'s [register()] method.');
}
/** @phpstan-ignore-next-line */
return $this->belongsTo(User::class);
return $this->belongsTo($userClass);
}
/**
+1 -1
View File
@@ -293,7 +293,7 @@ abstract class Importer
{
return static::$model ?? (string) str(class_basename(static::class))
->beforeLast('Importer')
->prepend('App\\Models\\');
->prepend(app()->getNamespace() . 'Models\\');
}
abstract public static function getCompletedNotificationBody(Import $import): string;
@@ -2,7 +2,6 @@
namespace Filament\Actions\Imports\Models;
use App\Models\User;
use Carbon\CarbonInterface;
use Exception;
use Filament\Actions\Imports\Importer;
@@ -64,12 +63,14 @@ class Import extends Model
return $this->belongsTo($authenticatable::class);
}
if (! class_exists(User::class)) {
throw new Exception('No [App\\Models\\User] model found. Please bind an authenticatable model to the [Illuminate\\Contracts\\Auth\\Authenticatable] interface in a service provider\'s [register()] method.');
$userClass = app()->getNamespace() . 'Models\\User';
if (! class_exists($userClass)) {
throw new Exception('No [' . $userClass . '] model found. Please bind an authenticatable model to the [Illuminate\\Contracts\\Auth\\Authenticatable] interface in a service provider\'s [register()] method.');
}
/** @phpstan-ignore-next-line */
return $this->belongsTo(User::class);
return $this->belongsTo($userClass);
}
/**
@@ -81,7 +81,7 @@ class MakeFormCommand extends Command
name: 'model-namespace',
shortcut: null,
mode: InputOption::VALUE_REQUIRED,
description: 'The namespace of the model class, [App\\Models] by default',
description: 'The namespace of the model class, [' . app()->getNamespace() . 'Models] by default',
),
new InputOption(
name: 'force',
@@ -134,7 +134,7 @@ class MakeFormCommand extends Command
->studly()
->replace('/', '\\');
$modelNamespace = $this->option('model-namespace') ?? 'App\\Models';
$modelNamespace = $this->option('model-namespace') ?? app()->getNamespace() . 'Models';
$this->modelFqn = "{$modelNamespace}\\{$this->modelFqnEnd}";
@@ -164,7 +164,7 @@ class MakeFormCommand extends Command
fn (string $class): bool => str($class)->replace(['\\', '/'], '')->contains($search, ignoreCase: true),
);
},
placeholder: 'App\\Models\\BlogPost',
placeholder: app()->getNamespace() . 'Models\\BlogPost',
required: true,
);
@@ -109,7 +109,7 @@ class MakeLivewireFormCommand extends Command
name: 'model-namespace',
shortcut: null,
mode: InputOption::VALUE_REQUIRED,
description: 'The namespace of the model class, [App\\Models] by default',
description: 'The namespace of the model class, [' . app()->getNamespace() . 'Models] by default',
),
new InputOption(
name: 'force',
@@ -166,7 +166,7 @@ class MakeLivewireFormCommand extends Command
->studly()
->replace('/', '\\');
$modelNamespace = $this->option('model-namespace') ?? 'App\\Models';
$modelNamespace = $this->option('model-namespace') ?? app()->getNamespace() . 'Models';
$this->modelFqn = "{$modelNamespace}\\{$this->modelFqnEnd}";
@@ -196,7 +196,7 @@ class MakeLivewireFormCommand extends Command
fn (string $class): bool => str($class)->replace(['\\', '/'], '')->contains($search, ignoreCase: true),
);
},
placeholder: 'App\\Models\\BlogPost',
placeholder: app()->getNamespace() . 'Models\\BlogPost',
required: true,
);
@@ -112,6 +112,8 @@ class PanelProviderClassGenerator extends ClassGenerator
$componentsDirectory = $isDefault ? '' : (Str::studly($id) . '/');
$componentsNamespace = $isDefault ? '' : (Str::studly($id) . '\\');
$rootNamespace = app()->getNamespace();
return new Literal(
<<<PHP
return \$panel{$defaultOutput}
@@ -120,12 +122,12 @@ class PanelProviderClassGenerator extends ClassGenerator
->colors([
'primary' => {$this->simplifyFqn(Color::class)}::Amber,
])
->discoverResources(in: app_path('Filament/{$componentsDirectory}Resources'), for: 'App\\Filament\\{$componentsNamespace}Resources')
->discoverPages(in: app_path('Filament/{$componentsDirectory}Pages'), for: 'App\\Filament\\{$componentsNamespace}Pages')
->discoverResources(in: app_path('Filament/{$componentsDirectory}Resources'), for: '{$rootNamespace}Filament\\{$componentsNamespace}Resources')
->discoverPages(in: app_path('Filament/{$componentsDirectory}Pages'), for: '{$rootNamespace}Filament\\{$componentsNamespace}Pages')
->pages([
{$this->simplifyFqn(Dashboard::class)}::class,
])
->discoverWidgets(in: app_path('Filament/{$componentsDirectory}Widgets'), for: 'App\\Filament\\{$componentsNamespace}Widgets')
->discoverWidgets(in: app_path('Filament/{$componentsDirectory}Widgets'), for: '{$rootNamespace}Filament\\{$componentsNamespace}Widgets')
->widgets([
{$this->simplifyFqn(AccountWidget::class)}::class,
{$this->simplifyFqn(FilamentInfoWidget::class)}::class,
@@ -159,7 +159,7 @@ class MakeClusterCommand extends Command
}
if (count($namespaces) < 2) {
$this->clustersNamespace = (Arr::first($namespaces) ?? 'App\\Filament\\Clusters');
$this->clustersNamespace = (Arr::first($namespaces) ?? app()->getNamespace() . 'Filament\\Clusters');
$this->clustersDirectory = (Arr::first($directories) ?? app_path('Filament/Clusters/'));
return;
@@ -149,7 +149,7 @@ class MakePageCommand extends Command
name: 'resource-namespace',
shortcut: null,
mode: InputOption::VALUE_OPTIONAL,
description: 'The namespace of the resource class, such as [App\\Filament\\Resources]',
description: 'The namespace of the resource class, such as [' . app()->getNamespace() . 'Filament\\Resources]',
),
new InputOption(
name: 'type',
@@ -336,7 +336,7 @@ class MakePageCommand extends Command
}
if (count($namespaces) < 2) {
$this->pagesNamespace = (Arr::first($namespaces) ?? 'App\\Filament\\Pages');
$this->pagesNamespace = (Arr::first($namespaces) ?? app()->getNamespace() . 'Filament\\Pages');
$this->pagesDirectory = (Arr::first($directories) ?? app_path('Filament/Pages/'));
return;
@@ -381,7 +381,7 @@ class MakePageCommand extends Command
->whenContains(
'Filament\\',
fn (Stringable $fqn) => $fqn->after('Filament\\')->prepend('Filament\\'),
fn (Stringable $fqn) => $fqn->replaceFirst('App\\', ''),
fn (Stringable $fqn) => $fqn->replaceFirst(app()->getNamespace(), ''),
)
->replace('\\', '/')
->explode('/')
@@ -584,7 +584,7 @@ class MakePageCommand extends Command
$formSchemaFqn = $this->askForSchema(
intialQuestion: 'Should an existing form schema class be used?',
question: 'Which form schema class would you like to use?',
questionPlaceholder: 'App\\Filament\\Resources\\Users\\Schemas\\UserForm',
questionPlaceholder: app()->getNamespace() . 'Filament\\Resources\\Users\\Schemas\\UserForm',
);
}
@@ -604,7 +604,7 @@ class MakePageCommand extends Command
$infolistSchemaFqn = $this->askForSchema(
intialQuestion: 'Would you like to use an existing infolist schema class?',
question: 'Which infolist schema class would you like to use?',
questionPlaceholder: 'App\\Filament\\Resources\\Users\\Schemas\\UserInfolist',
questionPlaceholder: app()->getNamespace() . 'Filament\\Resources\\Users\\Schemas\\UserInfolist',
);
}
@@ -621,7 +621,7 @@ class MakePageCommand extends Command
$tableFqn = $this->askForSchema(
intialQuestion: 'Would you like to use an existing table class?',
question: 'Which table class would you like to use?',
questionPlaceholder: 'App\\Filament\\Resources\\Users\\Tables\\UsersTable',
questionPlaceholder: app()->getNamespace() . 'Filament\\Resources\\Users\\Tables\\UsersTable',
);
}
@@ -206,7 +206,7 @@ class MakeRelationManagerCommand extends Command
name: 'resource-namespace',
shortcut: null,
mode: InputOption::VALUE_OPTIONAL,
description: 'The namespace of the resource class, such as [App\\Filament\\Resources]',
description: 'The namespace of the resource class, such as [' . app()->getNamespace() . 'Filament\\Resources]',
),
new InputOption(
name: 'soft-deletes',
@@ -401,7 +401,7 @@ class MakeRelationManagerCommand extends Command
: $this->askForSchema(
intialQuestion: 'Would you like to use an existing form schema class?',
question: 'Which form schema class would you like to use?',
questionPlaceholder: 'App\\Filament\\Resources\\Users\\Schemas\\UserForm',
questionPlaceholder: app()->getNamespace() . 'Filament\\Resources\\Users\\Schemas\\UserForm',
);
}
@@ -464,7 +464,7 @@ class MakeRelationManagerCommand extends Command
: $this->askForSchema(
intialQuestion: 'Would you like to use an existing infolist schema class?',
question: 'Which infolist schema class would you like to use?',
questionPlaceholder: 'App\\Filament\\Resources\\Users\\Schemas\\UserInfolist',
questionPlaceholder: app()->getNamespace() . 'Filament\\Resources\\Users\\Schemas\\UserInfolist',
);
}
@@ -481,7 +481,7 @@ class MakeRelationManagerCommand extends Command
: $this->askForSchema(
intialQuestion: 'Would you like to use an existing table class?',
question: 'Which table class would you like to use?',
questionPlaceholder: 'App\\Filament\\Resources\\Users\\Tables\\UsersTable',
questionPlaceholder: app()->getNamespace() . 'Filament\\Resources\\Users\\Tables\\UsersTable',
);
}
@@ -180,7 +180,7 @@ class MakeResourceCommand extends Command
name: 'model-namespace',
shortcut: null,
mode: InputOption::VALUE_REQUIRED,
description: 'The namespace of the model class, [App\\Models] by default',
description: 'The namespace of the model class, [' . app()->getNamespace() . 'Models] by default',
),
new InputOption(
name: 'nested',
@@ -211,7 +211,7 @@ class MakeResourceCommand extends Command
name: 'resource-namespace',
shortcut: null,
mode: InputOption::VALUE_OPTIONAL,
description: 'The namespace of the resource class, such as [App\\Filament\\Resources]',
description: 'The namespace of the resource class, such as [' . app()->getNamespace() . 'Filament\\Resources]',
),
new InputOption(
name: 'simple',
@@ -301,7 +301,7 @@ class MakeResourceCommand extends Command
$this->modelFqnEnd = 'Resource';
}
$modelNamespace = $this->option('model-namespace') ?? 'App\\Models';
$modelNamespace = $this->option('model-namespace') ?? app()->getNamespace() . 'Models';
$this->modelFqn = "{$modelNamespace}\\{$this->modelFqnEnd}";
} else {
@@ -321,7 +321,7 @@ class MakeResourceCommand extends Command
fn (string $class): bool => str($class)->replace(['\\', '/'], '')->contains($search, ignoreCase: true),
);
},
placeholder: 'App\\Models\\BlogPost',
placeholder: app()->getNamespace() . 'Models\\BlogPost',
required: true,
);
+20 -20
View File
@@ -844,9 +844,9 @@ class FilamentManager
}
/**
* @deprecated Use the `navigationGroups()` method on the panel configuration instead.
*
* @param array<string | int, NavigationGroup | string> $groups
*
* @deprecated Use the `navigationGroups()` method on the panel configuration instead.
*/
public function registerNavigationGroups(array $groups): void
{
@@ -858,9 +858,9 @@ class FilamentManager
}
/**
* @deprecated Use the `navigationItems()` method on the panel configuration instead.
*
* @param array<NavigationItem> $items
*
* @deprecated Use the `navigationItems()` method on the panel configuration instead.
*/
public function registerNavigationItems(array $items): void
{
@@ -872,9 +872,9 @@ class FilamentManager
}
/**
* @deprecated Use the `pages()` method on the panel configuration instead.
*
* @param array<class-string> $pages
*
* @deprecated Use the `pages()` method on the panel configuration instead.
*/
public function registerPages(array $pages): void
{
@@ -894,9 +894,9 @@ class FilamentManager
}
/**
* @deprecated Use the `resources()` method on the panel configuration instead.
*
* @param array<class-string> $resources
*
* @deprecated Use the `resources()` method on the panel configuration instead.
*/
public function registerResources(array $resources): void
{
@@ -908,9 +908,9 @@ class FilamentManager
}
/**
* @deprecated Register scripts using the `FilamentAsset` facade instead.
*
* @param array<mixed> $scripts
*
* @deprecated Register scripts using the `FilamentAsset` facade instead.
*/
public function registerScripts(array $scripts, bool $shouldBeLoadedBeforeCoreScripts = false): void
{
@@ -918,9 +918,9 @@ class FilamentManager
}
/**
* @deprecated Register script data using the `FilamentAsset` facade instead.
*
* @param array<string, mixed> $data
*
* @deprecated Register script data using the `FilamentAsset` facade instead.
*/
public function registerScriptData(array $data): void
{
@@ -928,9 +928,9 @@ class FilamentManager
}
/**
* @deprecated Register styles using the `FilamentAsset` facade instead.
*
* @param array<mixed> $styles
*
* @deprecated Register styles using the `FilamentAsset` facade instead.
*/
public function registerStyles(array $styles): void
{
@@ -950,9 +950,9 @@ class FilamentManager
}
/**
* @deprecated Use the `viteTheme()` method on the panel configuration instead.
*
* @param string | array<string> $theme
*
* @deprecated Use the `viteTheme()` method on the panel configuration instead.
*/
public function registerViteTheme(string | array $theme, ?string $buildDirectory = null): void
{
@@ -964,9 +964,9 @@ class FilamentManager
}
/**
* @deprecated Use the `userMenuItems()` method on the panel configuration instead.
*
* @param array<MenuItem> $items
*
* @deprecated Use the `userMenuItems()` method on the panel configuration instead.
*/
public function registerUserMenuItems(array $items): void
{
@@ -978,9 +978,9 @@ class FilamentManager
}
/**
* @deprecated Use the `widgets()` method on the panel configuration instead.
*
* @param array<class-string> $widgets
*
* @deprecated Use the `widgets()` method on the panel configuration instead.
*/
public function registerWidgets(array $widgets): void
{
+1 -1
View File
@@ -76,7 +76,7 @@ abstract class Resource
{
return static::$model ?? (string) str(class_basename(static::class))
->beforeLast('Resource')
->prepend('App\\Models\\');
->prepend(app()->getNamespace() . 'Models\\');
}
/**
@@ -188,7 +188,7 @@ class MakeSettingsPageCommand extends Command
return array_filter($settingsFqns, fn (string $modelFqn): bool => str($modelFqn)->replace(['\\', '/'], '')->contains($search, ignoreCase: true));
},
placeholder: 'App\\Settings\\SiteSettings',
placeholder: app()->getNamespace() . 'Settings\\SiteSettings',
hint: 'Please provide the fully-qualified class name.',
);
}
@@ -232,7 +232,7 @@ class MakeSettingsPageCommand extends Command
}
if (count($namespaces) < 2) {
$this->pagesNamespace = (Arr::first($namespaces) ?? 'App\\Filament\\Pages');
$this->pagesNamespace = (Arr::first($namespaces) ?? app()->getNamespace() . 'Filament\\Pages');
$this->pagesDirectory = (Arr::first($directories) ?? app_path('Filament/Pages/'));
return;
@@ -146,7 +146,7 @@ class SettingsPage extends Page
{
return static::$settings ?? (string) str(class_basename(static::class))
->beforeLast('Settings')
->prepend('App\\Settings\\')
->prepend(app()->getNamespace() . 'Settings\\')
->append('Settings');
}
@@ -23,14 +23,14 @@ trait CanAskForComponentLocation
if (blank($locations)) {
return [
"App\\Filament\\{$pathNamespace}",
app()->getNamespace() . "Filament\\{$pathNamespace}",
app_path('Filament' . DIRECTORY_SEPARATOR . $path),
'',
];
}
$options = [
null => "App\\Filament\\{$pathNamespace}",
null => app()->getNamespace() . "Filament\\{$pathNamespace}",
...array_map(
fn (string $namespace): string => "{$namespace}\\{$pathNamespace}",
array_combine(
@@ -47,7 +47,7 @@ trait CanAskForComponentLocation
if (blank($namespace)) {
return [
"App\\Filament\\{$pathNamespace}",
app()->getNamespace() . "Filament\\{$pathNamespace}",
app_path('Filament' . DIRECTORY_SEPARATOR . $path),
'',
];
@@ -21,14 +21,14 @@ trait CanAskForLivewireComponentLocation
if (blank($locations)) {
return [
'App\\Livewire',
app()->getNamespace() . 'Livewire',
app_path('Livewire'),
'',
];
}
$options = [
null => 'App\\Livewire',
null => app()->getNamespace() . 'Livewire',
...array_combine(
array_keys($locations),
array_keys($locations),
@@ -42,7 +42,7 @@ trait CanAskForLivewireComponentLocation
if (blank($namespace)) {
return [
'App\\Livewire',
app()->getNamespace() . 'Livewire',
app_path('Livewire'),
'',
];
@@ -35,7 +35,7 @@ trait CanAskForRelatedModel
return array_filter($modelFqns, fn (string $modelFqn): bool => str($modelFqn)->replace(['\\', '/'], '')->contains($search, ignoreCase: true));
},
placeholder: 'App\\Models\\User',
placeholder: app()->getNamespace() . 'Models\\User',
hint: 'Please provide the fully-qualified class name.',
);
}
@@ -60,7 +60,7 @@ trait CanAskForResource
if (! $resourceFqns) {
return (string) str(text(
label: "No resources were found within [{$resourcesNamespace}]. {$question}",
placeholder: 'App\\Filament\\Resources\\Posts\\PostResource',
placeholder: app()->getNamespace() . 'Filament\\Resources\\Posts\\PostResource',
required: true,
validate: function (string $value): ?string {
$value = (string) str($value)
@@ -44,7 +44,7 @@ trait CanGeneratePanels
throw new FailureCommandOutput;
}
$fqn = "App\\Providers\\Filament\\{$basename}";
$fqn = app()->getNamespace() . "Providers\\Filament\\{$basename}";
if (empty(Filament::getPanels())) {
$this->writeFile($path, app(PanelProviderClassGenerator::class, [
@@ -71,8 +71,8 @@ trait CanGeneratePanels
if (! Str::contains($appConfig, "{$fqn}::class")) {
file_put_contents(config_path('app.php'), str_replace(
'App\\Providers\\RouteServiceProvider::class,',
"{$fqn}::class," . PHP_EOL . ' App\\Providers\\RouteServiceProvider::class,',
app()->getNamespace() . 'Providers\\RouteServiceProvider::class,',
"{$fqn}::class," . PHP_EOL . ' ' . app()->getNamespace() . 'Providers\\RouteServiceProvider::class,',
$appConfig,
));
}
@@ -57,7 +57,7 @@ trait HasCluster
if (empty($clusterFqns)) {
$clusterFqn = (string) str(text(
label: "No clusters were found within the [{$this->panel->getId()}] panel. {$question}",
placeholder: 'App\\Filament\\Clusters\\Blog',
placeholder: app()->getNamespace() . 'Filament\\Clusters\\Blog',
required: true,
validate: function (string $value): ?string {
$value = (string) str($value)
@@ -44,7 +44,7 @@ trait HasResourcesLocation
if (count($namespaces) < 2) {
return [
(Arr::first($namespaces) ?? 'App\\Filament\\Resources'),
(Arr::first($namespaces) ?? app()->getNamespace() . 'Filament\\Resources'),
(Arr::first($directories) ?? app_path('Filament/Resources/')),
];
}
@@ -98,7 +98,7 @@ class MakeLivewireTableCommand extends Command
name: 'model-namespace',
shortcut: null,
mode: InputOption::VALUE_REQUIRED,
description: 'The namespace of the model class, [App\\Models] by default',
description: 'The namespace of the model class, [' . app()->getNamespace() . 'Models] by default',
),
new InputOption(
name: 'force',
@@ -153,7 +153,7 @@ class MakeLivewireTableCommand extends Command
->studly()
->replace('/', '\\');
$modelNamespace = $this->option('model-namespace') ?? 'App\\Models';
$modelNamespace = $this->option('model-namespace') ?? app()->getNamespace() . 'Models';
$this->modelFqn = "{$modelNamespace}\\{$this->modelFqnEnd}";
@@ -176,7 +176,7 @@ class MakeLivewireTableCommand extends Command
fn (string $class): bool => str($class)->replace(['\\', '/'], '')->contains($search, ignoreCase: true),
);
},
placeholder: 'App\\Models\\BlogPost',
placeholder: app()->getNamespace() . 'Models\\BlogPost',
required: true,
);
@@ -89,7 +89,7 @@ class MakeTableCommand extends Command
name: 'model-namespace',
shortcut: null,
mode: InputOption::VALUE_REQUIRED,
description: 'The namespace of the model class, [App\\Models] by default',
description: 'The namespace of the model class, [' . app()->getNamespace() . 'Models] by default',
),
new InputOption(
name: 'force',
@@ -143,7 +143,7 @@ class MakeTableCommand extends Command
->studly()
->replace('/', '\\');
$modelNamespace = $this->option('model-namespace') ?? 'App\\Models';
$modelNamespace = $this->option('model-namespace') ?? app()->getNamespace() . 'Models';
$this->modelFqn = "{$modelNamespace}\\{$this->modelFqnEnd}";
@@ -166,7 +166,7 @@ class MakeTableCommand extends Command
fn (string $class): bool => str($class)->replace(['\\', '/'], '')->contains($search, ignoreCase: true),
);
},
placeholder: 'App\\Models\\BlogPost',
placeholder: app()->getNamespace() . 'Models\\BlogPost',
required: true,
);
@@ -139,7 +139,7 @@ class MakeWidgetCommand extends Command
name: 'resource-namespace',
shortcut: null,
mode: InputOption::VALUE_OPTIONAL,
description: 'The namespace of the resource class, such as [App\\Filament\\Resources]',
description: 'The namespace of the resource class, such as [' . app()->getNamespace() . 'Filament\\Resources]',
),
new InputOption(
name: 'stats-overview',
@@ -329,7 +329,7 @@ class MakeWidgetCommand extends Command
}
if (count($namespaces) < 2) {
$this->widgetsNamespace = (Arr::first($namespaces) ?? 'App\\Filament\\Widgets');
$this->widgetsNamespace = (Arr::first($namespaces) ?? app()->getNamespace() . 'Filament\\Widgets');
$this->widgetsDirectory = (Arr::first($directories) ?? app_path('Filament/Widgets/'));
return;
@@ -486,7 +486,7 @@ class MakeWidgetCommand extends Command
fn (string $class): bool => str($class)->replace(['\\', '/'], '')->contains($search, ignoreCase: true),
);
},
placeholder: 'App\\Models\\BlogPost',
placeholder: app()->getNamespace() . 'Models\\BlogPost',
);
$isGenerated = confirm(
@@ -97,7 +97,7 @@ it('can generate a page class in a cluster', function (): void {
$this->artisan('make:filament-page', [
'name' => 'ManageSettings',
'--panel' => 'admin',
'--cluster' => 'App\\Filament\\Clusters\\Site',
'--cluster' => app()->getNamespace() . 'Filament\\Clusters\\Site',
'--no-interaction' => true,
]);
@@ -120,7 +120,7 @@ it('can generate a page view in a cluster', function (): void {
$this->artisan('make:filament-page', [
'name' => 'ManageSettings',
'--panel' => 'admin',
'--cluster' => 'App\\Filament\\Clusters\\Site',
'--cluster' => app()->getNamespace() . 'Filament\\Clusters\\Site',
'--no-interaction' => true,
]);
@@ -146,7 +146,7 @@ it('can generate a page class in a resource', function (): void {
invade(Filament::getCurrentOrDefaultPanel())->resources = [
...invade(Filament::getCurrentOrDefaultPanel())->resources,
'App\\Filament\\Resources\\UserResource',
app()->getNamespace() . 'Filament\\Resources\\UserResource',
];
$this->artisan('make:filament-page', [
@@ -179,7 +179,7 @@ it('can generate a page view in a resource', function (): void {
invade(Filament::getCurrentOrDefaultPanel())->resources = [
...invade(Filament::getCurrentOrDefaultPanel())->resources,
'App\\Filament\\Resources\\UserResource',
app()->getNamespace() . 'Filament\\Resources\\UserResource',
];
$this->artisan('make:filament-page', [
@@ -212,7 +212,7 @@ it('can generate a create page class in a resource', function (): void {
invade(Filament::getCurrentOrDefaultPanel())->resources = [
...invade(Filament::getCurrentOrDefaultPanel())->resources,
'App\\Filament\\Resources\\UserResource',
app()->getNamespace() . 'Filament\\Resources\\UserResource',
];
$this->artisan('make:filament-page', [
@@ -247,7 +247,7 @@ it('can generate an edit page class in a resource', function (): void {
invade(Filament::getCurrentOrDefaultPanel())->resources = [
...invade(Filament::getCurrentOrDefaultPanel())->resources,
'App\\Filament\\Resources\\UserResource',
app()->getNamespace() . 'Filament\\Resources\\UserResource',
];
$this->artisan('make:filament-page', [
@@ -282,7 +282,7 @@ it('can generate a view page class in a resource', function (): void {
invade(Filament::getCurrentOrDefaultPanel())->resources = [
...invade(Filament::getCurrentOrDefaultPanel())->resources,
'App\\Filament\\Resources\\UserResource',
app()->getNamespace() . 'Filament\\Resources\\UserResource',
];
$this->artisan('make:filament-page', [
@@ -334,8 +334,8 @@ $runGenerateManageRelatedRecordsPageCommand = function (TestCase $testCase): Pen
invade(Filament::getCurrentOrDefaultPanel())->resources = [
...invade(Filament::getCurrentOrDefaultPanel())->resources,
'App\\Filament\\Resources\\TeamResource',
'App\\Filament\\Resources\\UserResource',
app()->getNamespace() . 'Filament\\Resources\\TeamResource',
app()->getNamespace() . 'Filament\\Resources\\UserResource',
];
return $testCase->artisan('make:filament-page', [
@@ -385,8 +385,8 @@ it('can generate a manage related records page class in a resource with a relate
$runGenerateManageRelatedRecordsPageCommand($this)
->expectsQuestion($questions['relationship'], 'teams')
->expectsQuestion($questions['hasRelatedResource'], true)
->expectsQuestion($questions['relatedResource'], 'App\\Filament\\Resources\\TeamResource')
->expectsQuestion($questions['relatedResource'], 'App\\Filament\\Resources\\TeamResource'); // Repeat the question as there is a bug when testing `search()` in Prompts
->expectsQuestion($questions['relatedResource'], app()->getNamespace() . 'Filament\\Resources\\TeamResource')
->expectsQuestion($questions['relatedResource'], app()->getNamespace() . 'Filament\\Resources\\TeamResource'); // Repeat the question as there is a bug when testing `search()` in Prompts
assertFileExists($path = app_path('Filament/Resources/UserResource/Pages/ManageUserTeams.php'));
expect(file_get_contents($path))
@@ -47,8 +47,8 @@ beforeEach(function (): void {
invade(Filament::getCurrentOrDefaultPanel())->resources = [
...invade(Filament::getCurrentOrDefaultPanel())->resources,
'App\\Filament\\Resources\\TeamResource',
'App\\Filament\\Resources\\UserResource',
app()->getNamespace() . 'Filament\\Resources\\TeamResource',
app()->getNamespace() . 'Filament\\Resources\\UserResource',
];
MakeRelationManagerCommand::$shouldCheckModelsForSoftDeletes = false;
@@ -74,7 +74,7 @@ it('can generate a relation manager with a related resource', function (): void
$this->artisan('make:filament-relation-manager', [
'resource' => 'Users',
'relationship' => 'teams',
'--related-resource' => 'App\\Filament\\Resources\\TeamResource',
'--related-resource' => app()->getNamespace() . 'Filament\\Resources\\TeamResource',
'--panel' => 'admin',
'--no-interaction' => true,
]);
@@ -65,7 +65,7 @@ it('can generate a page class in a cluster', function (): void {
$this->artisan('make:filament-settings-page', [
'name' => 'ManageSettings',
'settings' => Settings::class,
'--cluster' => 'App\\Filament\\Clusters\\Site',
'--cluster' => app()->getNamespace() . 'Filament\\Clusters\\Site',
'--panel' => 'admin',
'--no-interaction' => true,
]);
@@ -88,7 +88,7 @@ it('can generate a page class in a cluster', function (): void {
$this->artisan('make:filament-page', [
'name' => 'ManageSettings',
'--panel' => 'admin',
'--cluster' => 'App\\Filament\\Clusters\\Site\\SiteCluster',
'--cluster' => app()->getNamespace() . 'Filament\\Clusters\\Site\\SiteCluster',
'--no-interaction' => true,
]);
@@ -111,7 +111,7 @@ it('can generate a page view in a cluster', function (): void {
$this->artisan('make:filament-page', [
'name' => 'ManageSettings',
'--panel' => 'admin',
'--cluster' => 'App\\Filament\\Clusters\\Site\\SiteCluster',
'--cluster' => app()->getNamespace() . 'Filament\\Clusters\\Site\\SiteCluster',
'--no-interaction' => true,
]);
@@ -137,7 +137,7 @@ it('can generate a page class in a resource', function (): void {
invade(Filament::getCurrentOrDefaultPanel())->resources = [
...invade(Filament::getCurrentOrDefaultPanel())->resources,
'App\\Filament\\Resources\\Users\\UserResource',
app()->getNamespace() . 'Filament\\Resources\\Users\\UserResource',
];
$this->artisan('make:filament-page', [
@@ -170,7 +170,7 @@ it('can generate a page view in a resource', function (): void {
invade(Filament::getCurrentOrDefaultPanel())->resources = [
...invade(Filament::getCurrentOrDefaultPanel())->resources,
'App\\Filament\\Resources\\Users\\UserResource',
app()->getNamespace() . 'Filament\\Resources\\Users\\UserResource',
];
$this->artisan('make:filament-page', [
@@ -203,7 +203,7 @@ it('can generate a create page class in a resource', function (): void {
invade(Filament::getCurrentOrDefaultPanel())->resources = [
...invade(Filament::getCurrentOrDefaultPanel())->resources,
'App\\Filament\\Resources\\Users\\UserResource',
app()->getNamespace() . 'Filament\\Resources\\Users\\UserResource',
];
$this->artisan('make:filament-page', [
@@ -238,7 +238,7 @@ it('can generate an edit page class in a resource', function (): void {
invade(Filament::getCurrentOrDefaultPanel())->resources = [
...invade(Filament::getCurrentOrDefaultPanel())->resources,
'App\\Filament\\Resources\\Users\\UserResource',
app()->getNamespace() . 'Filament\\Resources\\Users\\UserResource',
];
$this->artisan('make:filament-page', [
@@ -273,7 +273,7 @@ it('can generate a view page class in a resource', function (): void {
invade(Filament::getCurrentOrDefaultPanel())->resources = [
...invade(Filament::getCurrentOrDefaultPanel())->resources,
'App\\Filament\\Resources\\Users\\UserResource',
app()->getNamespace() . 'Filament\\Resources\\Users\\UserResource',
];
$this->artisan('make:filament-page', [
@@ -325,8 +325,8 @@ $runGenerateManageRelatedRecordsPageCommand = function (TestCase $testCase): Pen
invade(Filament::getCurrentOrDefaultPanel())->resources = [
...invade(Filament::getCurrentOrDefaultPanel())->resources,
'App\\Filament\\Resources\\Teams\\TeamResource',
'App\\Filament\\Resources\\Users\\UserResource',
app()->getNamespace() . 'Filament\\Resources\\Teams\\TeamResource',
app()->getNamespace() . 'Filament\\Resources\\Users\\UserResource',
];
return $testCase->artisan('make:filament-page', [
@@ -384,8 +384,8 @@ it('can generate a manage related records page class in a resource with a relate
$runGenerateManageRelatedRecordsPageCommand($this)
->expectsQuestion($questions['relationship'], 'teams')
->expectsQuestion($questions['hasRelatedResource'], true)
->expectsQuestion($questions['relatedResource'], 'App\\Filament\\Resources\\Teams\\TeamResource')
->expectsQuestion($questions['relatedResource'], 'App\\Filament\\Resources\\Teams\\TeamResource'); // Repeat the question as there is a bug when testing `search()` in Prompts
->expectsQuestion($questions['relatedResource'], app()->getNamespace() . 'Filament\\Resources\\Teams\\TeamResource')
->expectsQuestion($questions['relatedResource'], app()->getNamespace() . 'Filament\\Resources\\Teams\\TeamResource'); // Repeat the question as there is a bug when testing `search()` in Prompts
assertFileExists($path = app_path('Filament/Resources/Users/Pages/ManageUserTeams.php'));
expect(file_get_contents($path))
@@ -399,7 +399,7 @@ it('can generate a manage related records page class in a resource with a form s
->expectsQuestion($questions['relationship'], 'teams')
->expectsQuestion($questions['hasRelatedResource'], false)
->expectsQuestion($questions['hasFormSchemaClass'], true)
->expectsQuestion($questions['formSchemaClass'], 'App\\Filament\\Resources\\Teams\\Schemas\\TeamForm')
->expectsQuestion($questions['formSchemaClass'], app()->getNamespace() . 'Filament\\Resources\\Teams\\Schemas\\TeamForm')
->expectsQuestion($questions['hasViewOperation'], false)
->expectsQuestion($questions['hasTableClass'], false)
->expectsQuestion($questions['titleAttribute'], 'name')
@@ -463,7 +463,7 @@ it('can generate a manage related records page class in a resource with an infol
->expectsQuestion($questions['titleAttribute'], 'name')
->expectsQuestion($questions['hasViewOperation'], true)
->expectsQuestion($questions['hasInfolistSchemaClass'], true)
->expectsQuestion($questions['infolistSchemaClass'], 'App\\Filament\\Resources\\Teams\\Schemas\\TeamInfolist')
->expectsQuestion($questions['infolistSchemaClass'], app()->getNamespace() . 'Filament\\Resources\\Teams\\Schemas\\TeamInfolist')
->expectsQuestion($questions['hasTableClass'], false)
->expectsQuestion($questions['isSoftDeletable'], false)
->expectsQuestion($questions['relationshipType'], BelongsToMany::class);
@@ -484,7 +484,7 @@ it('can generate a manage related records page class in a resource with a table
->expectsQuestion($questions['titleAttribute'], 'name')
->expectsQuestion($questions['hasViewOperation'], false)
->expectsQuestion($questions['hasTableClass'], true)
->expectsQuestion($questions['tableClass'], 'App\\Filament\\Resources\\Teams\\Tables\\TeamsTable');
->expectsQuestion($questions['tableClass'], app()->getNamespace() . 'Filament\\Resources\\Teams\\Tables\\TeamsTable');
assertFileExists($path = app_path('Filament/Resources/Users/Pages/ManageUserTeams.php'));
expect(file_get_contents($path))
@@ -546,7 +546,7 @@ it('can generate a custom record page class in a resource', function (): void {
invade(Filament::getCurrentOrDefaultPanel())->resources = [
...invade(Filament::getCurrentOrDefaultPanel())->resources,
'App\\Filament\\Resources\\Users\\UserResource',
app()->getNamespace() . 'Filament\\Resources\\Users\\UserResource',
];
$this->mockConsoleOutput = true;
@@ -42,8 +42,8 @@ beforeEach(function (): void {
invade(Filament::getCurrentOrDefaultPanel())->resources = [
...invade(Filament::getCurrentOrDefaultPanel())->resources,
'App\\Filament\\Resources\\Teams\\TeamResource',
'App\\Filament\\Resources\\Users\\UserResource',
app()->getNamespace() . 'Filament\\Resources\\Teams\\TeamResource',
app()->getNamespace() . 'Filament\\Resources\\Users\\UserResource',
];
MakeRelationManagerCommand::$shouldCheckModelsForSoftDeletes = false;
@@ -69,7 +69,7 @@ it('can generate a relation manager with a related resource', function (): void
$this->artisan('make:filament-relation-manager', [
'resource' => 'Users',
'relationship' => 'teams',
'--related-resource' => 'App\\Filament\\Resources\\Teams\\TeamResource',
'--related-resource' => app()->getNamespace() . 'Filament\\Resources\\Teams\\TeamResource',
'--panel' => 'admin',
'--no-interaction' => true,
]);
@@ -85,7 +85,7 @@ it('can generate a relation manager with a form schema class', function (): void
'relationship' => 'teams',
'recordTitleAttribute' => 'name',
'--attach' => true,
'--form-schema' => 'App\\Filament\\Resources\\Teams\\Schemas\\TeamForm',
'--form-schema' => app()->getNamespace() . 'Filament\\Resources\\Teams\\Schemas\\TeamForm',
'--panel' => 'admin',
'--no-interaction' => true,
]);
@@ -134,7 +134,7 @@ it('can generate a relation manager with an infolist schema class', function ():
'relationship' => 'teams',
'recordTitleAttribute' => 'name',
'--attach' => true,
'--infolist-schema' => 'App\\Filament\\Resources\\Teams\\Schemas\\TeamInfolist',
'--infolist-schema' => app()->getNamespace() . 'Filament\\Resources\\Teams\\Schemas\\TeamInfolist',
'--view' => true,
'--panel' => 'admin',
'--no-interaction' => true,
@@ -151,7 +151,7 @@ it('can generate a relation manager with a table class', function (): void {
'relationship' => 'teams',
'recordTitleAttribute' => 'name',
'--attach' => true,
'--table' => 'App\\Filament\\Resources\\Teams\\Tables\\TeamsTable',
'--table' => app()->getNamespace() . 'Filament\\Resources\\Teams\\Tables\\TeamsTable',
'--panel' => 'admin',
'--no-interaction' => true,
]);
@@ -476,7 +476,7 @@ it('can generate a nested resource class', function (): void {
invade(Filament::getCurrentOrDefaultPanel())->resources = [
...invade(Filament::getCurrentOrDefaultPanel())->resources,
'App\\Filament\\Resources\\Users\\UserResource',
app()->getNamespace() . 'Filament\\Resources\\Users\\UserResource',
];
$this->artisan('make:filament-resource', [
@@ -506,7 +506,7 @@ it('can generate a nested resource class with a plural parent resource name', fu
invade(Filament::getCurrentOrDefaultPanel())->resources = [
...invade(Filament::getCurrentOrDefaultPanel())->resources,
'App\\Filament\\Resources\\Users\\UserResource',
app()->getNamespace() . 'Filament\\Resources\\Users\\UserResource',
];
$this->artisan('make:filament-resource', [
@@ -536,7 +536,7 @@ it('can generate a nested resource class with a parent resource name with `Resou
invade(Filament::getCurrentOrDefaultPanel())->resources = [
...invade(Filament::getCurrentOrDefaultPanel())->resources,
'App\\Filament\\Resources\\Users\\UserResource',
app()->getNamespace() . 'Filament\\Resources\\Users\\UserResource',
];
$this->artisan('make:filament-resource', [
@@ -566,7 +566,7 @@ it('can generate a nested resource form', function (): void {
invade(Filament::getCurrentOrDefaultPanel())->resources = [
...invade(Filament::getCurrentOrDefaultPanel())->resources,
'App\\Filament\\Resources\\Users\\UserResource',
app()->getNamespace() . 'Filament\\Resources\\Users\\UserResource',
];
$this->artisan('make:filament-resource', [
@@ -596,7 +596,7 @@ it('can generate a nested resource infolist', function (): void {
invade(Filament::getCurrentOrDefaultPanel())->resources = [
...invade(Filament::getCurrentOrDefaultPanel())->resources,
'App\\Filament\\Resources\\Users\\UserResource',
app()->getNamespace() . 'Filament\\Resources\\Users\\UserResource',
];
$this->artisan('make:filament-resource', [
@@ -627,7 +627,7 @@ it('can generate a nested resource create page', function (): void {
invade(Filament::getCurrentOrDefaultPanel())->resources = [
...invade(Filament::getCurrentOrDefaultPanel())->resources,
'App\\Filament\\Resources\\Users\\UserResource',
app()->getNamespace() . 'Filament\\Resources\\Users\\UserResource',
];
$this->artisan('make:filament-resource', [
@@ -657,7 +657,7 @@ it('can generate a nested resource edit page', function (): void {
invade(Filament::getCurrentOrDefaultPanel())->resources = [
...invade(Filament::getCurrentOrDefaultPanel())->resources,
'App\\Filament\\Resources\\Users\\UserResource',
app()->getNamespace() . 'Filament\\Resources\\Users\\UserResource',
];
$this->artisan('make:filament-resource', [
@@ -687,7 +687,7 @@ it('can generate a nested resource view page', function (): void {
invade(Filament::getCurrentOrDefaultPanel())->resources = [
...invade(Filament::getCurrentOrDefaultPanel())->resources,
'App\\Filament\\Resources\\Users\\UserResource',
app()->getNamespace() . 'Filament\\Resources\\Users\\UserResource',
];
$this->artisan('make:filament-resource', [
@@ -718,7 +718,7 @@ it('can generate a nested resource class in a nested directory', function (): vo
invade(Filament::getCurrentOrDefaultPanel())->resources = [
...invade(Filament::getCurrentOrDefaultPanel())->resources,
'App\\Filament\\Resources\\Users\\UserResource',
app()->getNamespace() . 'Filament\\Resources\\Users\\UserResource',
];
$this->artisan('make:filament-resource', [
@@ -59,7 +59,7 @@ it('can generate a page class in a cluster', function (): void {
$this->artisan('make:filament-settings-page', [
'name' => 'ManageSettings',
'settings' => Settings::class,
'--cluster' => 'App\\Filament\\Clusters\\Site\\SiteCluster',
'--cluster' => app()->getNamespace() . 'Filament\\Clusters\\Site\\SiteCluster',
'--panel' => 'admin',
'--no-interaction' => true,
]);
@@ -75,7 +75,7 @@ it('can generate a table class with a model in a custom namespace', function ():
$this->artisan('make:filament-table', [
'name' => 'PostsTable',
'model' => 'Post',
'--model-namespace' => 'App\\Models\\Blog',
'--model-namespace' => app()->getNamespace() . 'Models\\Blog',
'--no-interaction' => true,
]);
@@ -97,7 +97,7 @@ it('can generate a table widget class', function (): void {
'--no-interaction' => true,
])
->expectsQuestion('Would you like to create this widget in a resource?', false)
->expectsQuestion('What is the model?', 'App\\Models\\User')
->expectsQuestion('What is the model?', app()->getNamespace() . 'Models\\User')
->expectsQuestion('Should the table columns be generated from the current database columns?', false);
assertFileExists($path = app_path('Filament/Widgets/TableWidget.php'));