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.
You can install the package via Composer:
composer require annotation/laroute
'directories' => [
app_path('Http/Controllers/Backend'),
],
Only specify the scan path, no extended configuration information
'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
'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
use Annotation\Routing\Facades\Route;
Route::discover();
use Annotation\Routing\Facades\Route;
Route::discover(function (array $data, \Closure $next) {
return $next($data);
});
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
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
Nacosvel Contracts is made available under the MIT License (MIT). Please see License File for more information.