Home  >  Article  >  PHP Framework  >  Teach you to use the Laravel-Modules extension package to develop Laravel applications through modularization

Teach you to use the Laravel-Modules extension package to develop Laravel applications through modularization

藏色散人
藏色散人forward
2020-09-30 14:10:183749browse

下面由Laravel教程栏目给大家介绍使用 Laravel-Modules 扩展包通过模块化开发 Laravel 应用,希望对需要的朋友有所帮助!

Teach you to use the Laravel-Modules extension package to develop Laravel applications through modularization

  1. 首先在 Laravel 项目根目录下使用 Composer 安装该扩展包:
	composer require nwidart/laravel-modules
  1. 如不需要发布配置文件可以不用运行这条命令。该扩展包会自动注册服务提供者和别名。此外,你可以通过运行如下命令来发布配置文件:
	php artisan vendor:publish --provider="Nwidart\Modules\LaravelModulesServiceProvider"
  1. 执行命令,创建一个modules并新建Blog模块。也可以同时创建多个模块,如Blog、User模块 :
	php artisan module:make Blog
	php artisan module:make Blog User
  1. 让模块目录中定义的类可以自动加载,可以这样配置 composer.json:
	{
		  "autoload": {
			    "psr-4": {
			      "App\\": "app/",
			      "Modules\\": "Modules/"
			    }
		  }
	}
  1. 配置完成后不要忘记运行 composer dump-autoload 命令让修改生效

The above is the detailed content of Teach you to use the Laravel-Modules extension package to develop Laravel applications through modularization. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete