annotation / laroute
Auto register routes using PHP attributes for Laravel.
Installs: 1 043
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: ^8.0
- reflective/reflection: ^2.0
- rfc/request: ^1.0
This package is auto-updated.
Last update: 2025-05-28 14:36:39 UTC
README
Using PHP 8 attributes to automatically generate routes in order to streamline Laravel routing, enhancing developer productivity while maintaining full compatibility with Laravel's routing functionality.
Installation
You can install the package via Composer:
composer require annotation/laroute
Usage
Directories Configurations
'directories' => [ app_path('Http/Controllers/Backend'), ],
Only specify the scan path, no extended configuration information
Basic Configuration
'directories' => [ app_path('Http/Controllers/Backend') => [ 'domain' => env('LAROUTE_DOMAINS_BACKEND', 'backend.lvh.me'), 'prefix' => 'backend', 'as' => 'backend.', 'middleware' => 'web', // Only routes matching the pattern in the file are registered 'only' => ['*Controller.php'], // Except routes from registration pattern matching file 'except' => [], ], ],
More configurations of
domain
,prefix
,as
, andmiddleware
can be specified
Multiple Configurations
'directories' => [ app_path('Http/Controllers/Enterprise') => [ [ 'domain' => env('LAROUTE_DOMAINS_ENTERPRISE', 'enterprise.lvh.me'), 'prefix' => 'enterprise', 'as' => 'enterprise.', 'middleware' => [ 'web', 'auth', ], // Only routes matching the pattern in the file are registered 'only' => ['*Controller.php'], // Except routes from registration pattern matching file 'except' => ['AccountController.php'], ], [ 'domain' => env('LAROUTE_DOMAINS_ENTERPRISE', 'enterprise.lvh.me'), 'prefix' => 'enterprise', 'as' => 'enterprise.', 'middleware' => [ 'web', ], // Only routes matching the pattern in the file are registered 'only' => ['AccountController.php'], // Except routes from registration pattern matching file 'except' => [], ], ], ],
The same path can specify multiple groups of configurations, suitable for scenarios such as
Auth
andGuest
routing
Route Discover
Basic usage
use Annotation\Routing\Facades\Route; Route::discover();
Route discover monitoring
use Annotation\Routing\Facades\Route; Route::discover(function (array $data, \Closure $next) { return $next($data); });
Gateway Routing
use Annotation\Routing\Facades\Route; Route::gateWay('gateway.do', function (Request $request) { return $request->get('action'); });
Specify the route to get the named source
use Annotation\Routing\Facades\Route; Route::gateWay('gateway.do', function (Request $request) { return $request->get('action'); }, function (Request $request) { return $request->get('version'); });
Specify the route to obtain the version source
Command Support
php artisan route.scan:cache
Create a scanned route cache file for faster route registration
php artisan route.scan:clear
Remove the scanned route cache file
License
Nacosvel Contracts is made available under the MIT License (MIT). Please see License File for more information.