poshtive/router
Composer 安装命令:
composer require poshtive/router
包简介
Convention-based route discovery for Laravel controllers using PHP attributes.
README 文档
README
Convention-based route discovery for Laravel controllers, with PHP attributes for overrides and metadata.
Status
laravel-router is stable.
- PHP:
^8.3 - Laravel components:
^12.0|^13.0 - Test coverage: PHPUnit 11 + Orchestra Testbench 10/11, with
src/at 100% locally
Highlights
- Public-method route discovery with minimal registration boilerplate
- Support for nested controller resources and model-bound parameters
- Convention-based HTTP verb resolution with optional explicit overrides
- Middleware,
whereconstraints, and inheritance-aware discovery - Strict duplicate detection and optional skipped-route reporting
Installation
Install the package with Composer:
composer require poshtive/router
Optionally publish the configuration file:
php artisan vendor:publish --provider="Poshtive\Router\RouterServiceProvider" --tag="config"
Quick Start
Configure route discovery in config/router.php:
'groups' => [ 'web' => [ 'paths' => [app_path('Http/Controllers')], 'middleware' => ['web'], ], ],
Then add a controller method:
namespace App\Http\Controllers; class UserController { public function index() {} }
This registers GET /user automatically after the service provider boots.
You can still define Laravel routes manually as usual.
A Complete Example
Keep web and API controllers in separate directories when they use different middleware or URL prefixes. For example, configure an API group like this:
// config/router.php 'groups' => [ 'api' => [ 'paths' => [app_path('Http/Controllers/Api')], 'prefix' => 'api', 'name' => 'api.', 'middleware' => ['api'], ], ],
Then add app/Http/Controllers/Api/UserController.php:
namespace App\Http\Controllers\Api; use App\Models\User; use Poshtive\Router\Attributes\Route; class UserController { public function index() {} public function show(User $user) {} #[Route(method: 'POST')] public function store() {} #[Route(method: ['PUT', 'PATCH'])] public function update(User $user) {} }
With the default attribute_or_get convention, discovery registers:
| Method | URI | Name |
|---|---|---|
GET |
/api/user |
api.user.index |
GET |
/api/user/{user}/show |
api.user.show |
POST |
/api/user/store |
api.user.store |
PUT, PATCH |
/api/user/{user}/update |
api.user.update |
The User $user type hint supplies the {user} binding placeholder. Laravel
resolves the model after the route is registered. Method names default to GET;
use #[Route(method: ...)] or http_methods_map for other verbs.
Documentation
Testing
Run the package test suite with:
composer test
Generate a Clover coverage report for src/ with:
composer test:coverage
Changelog
Release notes are tracked in CHANGELOG.md.
Contributing
Contributions are welcome. Please feel free to submit issues or pull requests.
License
This package is open-sourced software licensed under the MIT license.
poshtive/router 适用场景与选型建议
poshtive/router 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 410 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 09 月 15 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「routing」 「router」 「attributes」 「laravel」 「discovery」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 poshtive/router 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 poshtive/router 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 poshtive/router 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Write down your routing mapping at one place
A library that allows you to easily use the PHP-VCR library in your PHPUnit tests.
This Package provides some usefully console features like the attribute syntax for arguments and options, validation, auto ask and casting.
Flight routing is a simple, fast PHP router that is easy to get integrated with other routers.
Router
The last validation library you will ever need!
统计信息
- 总下载量: 410
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 18
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-09-15