Skip to main content

介绍

nwidart/laravel-modules 是一个模块化开发大型 Laravel 应用的扩展包。 一个模块,有点类似于扩展包,它包含了视图、控制器或者模型。本扩展包支持Laravel 9。

扩展包是 pingpong/modules 的升级版。但是与原扩展包最大的区别就是:tests

AsgardCMS 就是使用了本扩展包进行模块化管理和开发。

至于为何要使用本扩展包,你可以参考文章:使用laravel-modules开发模块化应用

注意:如果您从以前的版本升级到 v6,请运行以下命令: php artisan module:v6:migrate

v8.3.0 升级

If you have an existing config file, and you get an error:

Target class [CommandMakeCommand] does not exist

Then the config file will need updating first import the commands class:

use Nwidart\Modules\Commands;

Next replace the commands array with:

'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,
],

Quick Example

Generate your first module using php artisan module:make Blog. The following structure will be generated.

Modules/
  ├── Blog/
      ├── Config/
      ├── Console/
      ├── Database/
          ├── factories/
          ├── Migrations/
          ├── Seeders/
      ├── Entities/
      ├── Http/
          ├── Controllers/
          ├── Middleware/
          ├── Requests/
      ├── Providers/
          ├── BlogServiceProvider.php
          ├── RouteServiceProvider.php
      ├── Resources/
          ├── assets/
          ├── lang/
          ├── views/
      ├── Routes/
          ├── api.php
          ├── web.php
      ├── Tests/
      ├── composer.json
      ├── module.json
      ├── package.json
      ├── webpack.mix.js