g4t/easyroute
Composer 安装命令:
composer require g4t/easyroute
包简介
Modern Laravel 13 routing using PHP 8 attributes with auto-generation, nested controller support, and native route caching.
关键字:
README 文档
README
🌟 Laravel 13 G4T easyRoute Attributes
A Laravel 13 package that lets you define routes using PHP 8 attributes with full support for Controller-level routes, Method-level routes, middleware, subfolders, and caching via Laravel’s routes-v7.php.
🚀 Features
- Controller-level route attributes (
#[Route(uri: 'users')]) - Method-level route attributes (
#[Get],#[Post],#[Put],#[Patch],#[Delete],#[Any]) - Auto route generation using method names or
onControlleroption - Middleware support (controller-level + method-level)
- Nested folder support for controllers
- Route caching using Laravel compiled routes (
bootstrap/cache/routes-v7.php) - Configurable Controllers paths
⚙️ Installation
Install via Composer:
composer require g4t/easyroute
Publish config:
php artisan vendor:publish --provider "G4T\EaseRoute\EaseRouteServiceProvider"
This creates config/route-attribute.php:
return [ 'controllers_path' => [app_path('Http/Controllers')], 'cache' => true, ];
📝 Usage Controller-level Route
<?php namespace App\Http\Controllers; use G4T\EaseRoute\Attributes\Route; use G4T\EaseRoute\Attributes\Get; use G4T\EaseRoute\Attributes\Post; #[Route(uri: 'users', middleware: ['auth'])] class UserController extends Controller { #[Get] public function index() { return "List of users"; } #[Get(onController: true)] public function show($id) { return "User: $id"; } #[Post('create')] public function store() { return "Create user"; } }
Supported HTTP Methods
| Attribute | HTTP Method |
|---|---|
| #[Get] | GET |
| #[Post] | POST |
| #[Put] | PUT |
| #[Patch] | PATCH |
| #[Delete] | DELETE |
| #[Any] | Any method |
⚡ Route Caching
To improve performance, EasyRoute can use Laravel compiled routes instead of scanning controllers for every request.
Steps:
- Ensure cache is enabled in
config/route-attribute.php:
'cache' => true
- Run the caching command:
php artisan route:cache
⚙️ Configuration
return [ 'controllers_path' => [app_path('Http/Controllers')], 'cache' => true, ];
controllers_path→ Array of paths where your controllers residecache→ Use cached routes from routes-v7.php
📝 Notes Supports nested folders in controllers_path.
Use onController: true to auto-generate URI based on Controller and Method names.
Middleware is merged: controller-level + method-level.
Fully compatible with Laravel 13 attributes syntax.
GET users UserController@index GET user/show/{id} UserController@show POST users/create UserController@store
app/ ├─ Http/ │ ├─ Controllers/ │ │ ├─ UserController.php │ │ └─ Admin/ │ │ └─ AdminController.php bootstrap/ └─ cache/ └─ routes-v7.php config/ └─ route-attribute.php
✅ Notes for Developers
- Place your controllers inside controllers_path
- Add #[Route(...)] at the class level
- Add #[Get], #[Post], etc. at method level
- Use onController: true for automatic route naming
Run
php artisan route:cacheto generate cached routes
EasyRoute makes your Laravel 13 routing modern, clean, and high-performance.
g4t/easyroute 适用场景与选型建议
g4t/easyroute 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4 次下载、GitHub Stars 达 1, 最近一次更新时间为 2026 年 03 月 23 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「routing」 「attributes」 「laravel」 「clean-code」 「route-attributes」 「laravel 13」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 g4t/easyroute 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 g4t/easyroute 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 g4t/easyroute 相关的其它包
同方向 / 同关键字的高下载量 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.
The last validation library you will ever need!
A PHPDoc docblock interpreter that is simple, easy to use, and provides Attribute alternatives.
统计信息
- 总下载量: 4
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 30
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-03-23


