ricventu/laravel-route-maze
最新稳定版本:v1.1.4
Composer 安装命令:
composer require ricventu/laravel-route-maze
包简介
A quick and easy way to create the routes is to take advantage of the convention over configuration
README 文档
README
Warning
This project is archived and no longer maintained.
Please use spatie/laravel-route-discovery instead, which I have contributed to and provides the same convention-over-configuration approach to route generation.
A quick and easy way to auto generate routes, is to take advantage of the convention over configuration and PHP attributes.
This means that routes are automatically generated based on the directory structure of the controllers and the methods attributes.
In this way, you don't have to manually write the routes in the web.php or api.php file, but just follow some rules of file naming and organization.
Route groups are base on subdirectories of the controllers.
Let's see how to do it with a practical example.
Controller: App/Http/Controllers/SomeCategory/ProductsController.php
class ProductsController { // index and __invoke defaults to GET public function index() {...} #[Get] public function show($id) {...} #[Post] public function store(Request $request) {...} #[Patch] public function update($id, Request $request) {...} #[Delete] public function destroy($id) {...} }
To get routes simpli add the the following line to routes/web.php
Route::maze(app_path('Http/Controllers'), 'App\\Http\\Controllers');
The generated routes are:
Route::get('/some-category/products', 'SomeCategory\ProductsController@index')->name('some-category.products'); Route::get('/some-category/products/show/{id}', 'SomeCategory\ProductsController@show')->name('some-category.products.show'); Route::post('/some-category/products/store', 'SomeCategory\ProductsController@store')->name('some-category.products.store'); Route::Patch('/some-category/products/update/{id}', 'SomeCategory\ProductsController@update')->name('some-category.products.update'); Route::delete('/some-category/products/destroy/{id}', 'SomeCategory\ProductsController@destroy')->name('some-category.products.destroy');
Parameters in path
Parameters can be specified in the path naming the directory with _param-name_.
Http/Controllers/_param1_/ItemsController.php
class ItemsController { #[Get] public function get($id) {...} }
becomes
Route::get('/{param1}/items/get/{id}', 'ItemsController@get')->name('items.get');
Middleware
You can specify middleware group by adding a file named middleware.php in the controller directory.
return [ 'auth', ];
Naming conventions
Uri and route name are composed of directories name, first part of the controller name (before Controller) and method name, all in kebab-case.
examples:
| Controller name | Method name | Route name | Route path |
|---|---|---|---|
| SomeProductController | showItem($id) | some.product.show-item | /some-product/show-item/{id} |
| SomeProductController | storeItem | some.product.store-item | /some-product/store-item |
| SomeProductController | updateItem($id) | some.product.update-item | /some-product/update-item/{id} |
| SomeProductController | destroyItem($id) | some.product.destroy-item | /some-product/destroy-item/{id} |
Disable discover for a Controller
To disable route discover for a specified crontroller, add static method mazeDisabled that returns true
In path configuration
If in the path is present a file named maze.php, it will be used to configure the route group.
return [
];
| Key | Description | Default |
|---|---|---|
| ignore_path_name | Ignore path and name in route | false |
| disabled | Disable discovering of the entire path |
## Installation You can install the package via composer: ```bash composer require ricventu/laravel-route-maze
Usage
Route::maze(app_path('Http/Controllers'), 'App\\Http\\Controllers');
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Performance note
In production deployment, it's recommended to cache route discovering using Laravel route:cache built in command
Credits
License
The MIT License (MIT). Please see License File for more information.
ricventu/laravel-route-maze 适用场景与选型建议
ricventu/laravel-route-maze 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 892 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 11 月 23 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「ricventu」 「laravel-route-maze」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 ricventu/laravel-route-maze 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ricventu/laravel-route-maze 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 ricventu/laravel-route-maze 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
统计信息
- 总下载量: 892
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 14
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-11-23