vaened/laravel-route-moduler

v2.0 2024-08-06 18:35 UTC

This package is auto-updated.

Last update: 2024-09-09 19:04:06 UTC


README

Build Status Software License

按模块和子模块分离Laravel路由

└── routes
    └── api
        └── clients.php
        └── payments.php
        └── store.php

安装

Laravel Route Moduler需要PHP 8.2。要获取最新版本,只需使用Composer要求项目即可。

composer require vaened/laravel-route-moduler

现在。发布配置文件。

php artisan vendor:publish --tag='laravel-route-moduler'

使用方法

一旦安装了库,你就可以开始在默认位置的路由/modules文件夹内组织你的路由。如果你喜欢不同的位置,你可以在route-modules.php配置文件中更新它。

├── routes
    └── modules

多个模块

route-modules.php配置文件为单个模块设置返回一个数组。但是,你可以通过扩展这个数组来配置你需要的任何数量的模块。

└── routes
    └── api
    └── web
    └── app

这种结构有助于保持你的应用程序路由的组织,使得维护和扩展变得更加容易。

配置

您可以通过route-modules.php配置文件自定义laravel-route-moduler包的行为。以下是一些可用的选项

path:指定模块的路由配置文件的位置。您可以将此设置为目录或单个文件。

Example:
	Load all routes in a directory: 'path' => 'routes/modules'
	Single route file: 'path' => 'routes/users.php'

prefix:在创建模块时向模块路径添加前缀,有助于使模块独立并补充文件名前缀。

Example: 
	'prefix' => 'admin'

named:如果为true,则将路由文件名用作该文件中定义的路由的前缀。

Example: 
	If the file is users.php, all routes will be prefixed with users.

middleware:定义应用于模块注册的所有路由的默认中间件。

Example: 
	'middleware' => ['web', 'auth']

这些设置允许您根据应用程序的特定路由需求调整包。

许可协议

此库采用MIT许可协议。有关更多信息,请参阅license文件。