配置
配置
你可以使用以下命令发布包配置:
php artisan vendor:publish --provider="Nwidart\Modules\LaravelModulesServiceProvider"
在发布的配置文件中,您可以配置以下内容:
默认 namespace
生成模块时的默认命名空间是什么。
默认: Modules
这将为该模块在创建时以及稍后生成其他类时使用该命名空间。
覆盖生成的文件(存根)
覆盖生成模块时使用的默认生成存根。这对于自定义不同文件的输出很有用。
这些存根设置选项和路径。
启用 true 或 fals e将在创建时启用或禁用模块,默认值为 false 意味着您必须手动启用模块。
启用模块编辑 module_statuses.json 或者运行命令:
php artisan module:enable ModuleName
注意:如果
module_statues.json
文件不存在,则使用此命令创建文件。
module_statuses.json
的内容看起来像这样:
{
"Users": true
}
上述情况发生在只有一个名为Users的模块并启用时。
Path 直接指向默认存根所在的供应商,这些存根可以被发布和修改。
Files 设置文件默认位置。
Replacements 是一种查找和替换的方法,在生成时,任何匹配都将被替换。
'stubs' => [
'enabled' => false,
'path' => base_path() . '/vendor/nwidart/laravel-modules/src/Commands/stubs',
'files' => [
'routes/web' => 'Routes/web.php',
'routes/api' => 'Routes/api.php',
'views/index' => 'Resources/views/index.blade.php',
'views/master' => 'Resources/views/layouts/master.blade.php',
'scaffold/config' => 'Config/config.php',
'composer' => 'composer.json',
'assets/js/app' => 'Resources/assets/js/app.js',
'assets/sass/app' => 'Resources/assets/sass/app.scss',
'webpack' => 'webpack.mix.js',
'package' => 'package.json',
],
'replacements' => [
'routes/web' => ['LOWER_NAME', 'STUDLY_NAME'],
'routes/api' => ['LOWER_NAME'],
'webpack' => ['LOWER_NAME'],
'json' => ['LOWER_NAME', 'STUDLY_NAME', 'MODULE_NAMESPACE', 'PROVIDER_NAMESPACE'],
'views/index' => ['LOWER_NAME'],
'views/master' => ['LOWER_NAME', 'STUDLY_NAME'],
'scaffold/config' => ['STUDLY_NAME'],
'composer' => [
'LOWER_NAME',
'STUDLY_NAME',
'VENDOR',
'AUTHOR_NAME',
'AUTHOR_EMAIL',
'MODULE_NAMESPACE',
'PROVIDER_NAMESPACE',
],
],
'gitkeep' => true,
],
生成路径
默认情况下,这些是默认生成的文件,其中 generate
设置为 true ,如果使用 false ,则不生成路径。
不喜欢在模型中使用实体,这里你可以更改模型的路径。
'generator' => [
'config' => ['path' => 'Config', 'generate' => true],
'command' => ['path' => 'Console', 'generate' => true],
'migration' => ['path' => 'Database/Migrations', 'generate' => true],
'seeder' => ['path' => 'Database/Seeders', 'generate' => true],
'factory' => ['path' => 'Database/factories', 'generate' => true],
'model' => ['path' => 'Entities', 'generate' => true],
'routes' => ['path' => 'Routes', 'generate' => true],
'controller' => ['path' => 'Http/Controllers', 'generate' => true],
'filter' => ['path' => 'Http/Middleware', 'generate' => true],
'request' => ['path' => 'Http/Requests', 'generate' => true],
'provider' => ['path' => 'Providers', 'generate' => true],
'assets' => ['path' => 'Resources/assets', 'generate' => true],
'lang' => ['path' => 'Resources/lang', 'generate' => true],
'views' => ['path' => 'Resources/views', 'generate' => true],
'test' => ['path' => 'Tests/Unit', 'generate' => true],
'test-feature' => ['path' => 'Tests/Feature', 'generate' => true],
'repository' => ['path' => 'Repositories', 'generate' => false],
'event' => ['path' => 'Events', 'generate' => false],
'listener' => ['path' => 'Listeners', 'generate' => false],
'policies' => ['path' => 'Policies', 'generate' => false],
'rules' => ['path' => 'Rules', 'generate' => false],
'jobs' => ['path' => 'Jobs', 'generate' => false],
'emails' => ['path' => 'Emails', 'generate' => false],
'notifications' => ['path' => 'Notifications', 'generate' => false],
'resource' => ['path' => 'Transformers', 'generate' => false],
'component-view' => ['path' => 'Resources/views/components', 'generate' => false],
'component-class' => ['path' => 'View/Component', 'generate' => false],
]
包的命令
你可以运行的命令在这个列表中。任何你不想使用的命令都可以被注释掉或从列表中删除,并且在运行 php artisan
时将不可见。
'commands' => [
Commands\CommandMakeCommand::class,
Commands\ComponentClassMakeCommand::class,
Commands\ComponentViewMakeCommand::class,
Commands\ControllerMakeCommand::class,
Commands\DisableCommand::class,
Commands\DumpCommand::class,
Commands\EnableCommand::class,
Commands\EventMakeCommand::class,
Commands\JobMakeCommand::class,
Commands\ListenerMakeCommand::class,
Commands\MailMakeCommand::class,
Commands\MiddlewareMakeCommand::class,
Commands\NotificationMakeCommand::class,
Commands\ProviderMakeCommand::class,
Commands\RouteProviderMakeCommand::class,
Commands\InstallCommand::class,
Commands\ListCommand::class,
Commands\ModuleDeleteCommand::class,
Commands\ModuleMakeCommand::class,
Commands\FactoryMakeCommand::class,
Commands\PolicyMakeCommand::class,
Commands\RequestMakeCommand::class,
Commands\RuleMakeCommand::class,
Commands\MigrateCommand::class,
Commands\MigrateRefreshCommand::class,
Commands\MigrateResetCommand::class,
Commands\MigrateRollbackCommand::class,
Commands\MigrateStatusCommand::class,
Commands\MigrationMakeCommand::class,
Commands\ModelMakeCommand::class,
Commands\PublishCommand::class,
Commands\PublishConfigurationCommand::class,
Commands\PublishMigrationCommand::class,
Commands\PublishTranslationCommand::class,
Commands\SeedCommand::class,
Commands\SeedMakeCommand::class,
Commands\SetupCommand::class,
Commands\UnUseCommand::class,
Commands\UpdateCommand::class,
Commands\UseCommand::class,
Commands\ResourceMakeCommand::class,
Commands\TestMakeCommand::class,
Commands\LaravelModulesV6Migrator::class,
Commands\ComponentClassMakeCommand::class,
Commands\ComponentViewMakeCommand::class,
],
覆盖路径
覆盖整个包中使用的默认路径。
设置放置模块文件夹的路径、发布资源的位置以及迁移的位置。
建议保持默认值。
'paths' => [
'modules' => base_path('Modules'),
'assets' => public_path('modules'),
'migration' => base_path('database/migrations'),
]
扫描其他文件夹查找模块
默认情况下,模块除了从扫描路径加载外,还从名为 modules
的目录加载。任何为模块安装的包都可以从这里加载。
'scan' => [
'enabled' => false,
'paths' => [
base_path('vendor/*/*'),
],
],
你可以添加自己的位置,例如,你正在构建一个大型应用程序,并希望有多个模块文件夹位置,你可以根据需要创建多个。
'scan' => [
'enabled' => true,
'paths' => [
base_path('ModulesCms'),
base_path('ModulesERP'),
base_path('ModulesShop'),
],
],
记住要将 enabled 设置为 true 才能启用这些位置。
Composer文件模板
当生成一个模块时,composer.json
文件将包含如下所示的作者详细信息,根据需要更改它们。
请特别注意供应商,如果你计划稍后将模块提取为包,建议在这里使用你的 BitBucket / GitHub / GitLab 名称。
'composer' => [
'vendor' => 'nwidart',
'author' => [
'name' => 'Nicolas Widart',
'email' => 'n.widart@gmail.com',
],
]
缓存
如果你有很多模块,最好缓存这些信息 (如多个 module.json
文件)。
模块可以缓存,默认情况下缓存是关闭的。
'cache' => [
'enabled' => false,
'key' => 'laravel-modules',
'lifetime' => 60,
],
注册自定义命名空间
决定包需要注册哪些自定义命名空间。如果其中一个设置为 false ,该包将不会处理其注册。
推荐文章: