g4t / easyroute
Modern Laravel 13 routing using PHP 8 attributes with auto-generation, nested controller support, and native route caching.
Requires
- php: >=8.2
- illuminate/routing: ^13.0
- illuminate/support: ^13.0
Requires (Dev)
- orchestra/testbench: ^4.0|^5.0|^6.0
- phpunit/phpunit: ^8.4|^9.0
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.


