{"id":15027278,"url":"https://github.com/twirelab/laravel-router","last_synced_at":"2025-04-09T20:21:55.653Z","repository":{"id":188542980,"uuid":"678955136","full_name":"Twirelab/laravel-router","owner":"Twirelab","description":"The new way of routing for the Laravel framework","archived":false,"fork":false,"pushed_at":"2024-11-15T11:26:21.000Z","size":38,"stargazers_count":12,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-23T22:13:57.248Z","etag":null,"topics":["annotation","annotations","laravel","php81","php82","router","routing","twirelab"],"latest_commit_sha":null,"homepage":"https://twirelab.com","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Twirelab.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-08-15T19:20:49.000Z","updated_at":"2024-11-15T11:25:27.000Z","dependencies_parsed_at":null,"dependency_job_id":"50ed7385-c0b7-41be-afe4-5f26b096655d","html_url":"https://github.com/Twirelab/laravel-router","commit_stats":{"total_commits":11,"total_committers":1,"mean_commits":11.0,"dds":0.0,"last_synced_commit":"e8d775db3fd31f1163162743e86b1708efd3b4f9"},"previous_names":["twirelab/laravel-router"],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Twirelab%2Flaravel-router","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Twirelab%2Flaravel-router/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Twirelab%2Flaravel-router/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Twirelab%2Flaravel-router/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Twirelab","download_url":"https://codeload.github.com/Twirelab/laravel-router/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248104552,"owners_count":21048359,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["annotation","annotations","laravel","php81","php82","router","routing","twirelab"],"created_at":"2024-09-24T20:06:07.297Z","updated_at":"2025-04-09T20:21:55.594Z","avatar_url":"https://github.com/Twirelab.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Laravel Router\n\n\u003e Attention! This package is not suitable for use in production.\n\nThe router is a new way of defining routes in the Laravel framework using annotations.\n\n**Requirements**\n- Laravel 8 or above.\n- PHP 8.1 or above.\n\n## Installation\n1. Install the package via composer\n```shell\ncomposer require twirelab/laravel-router\n```\n\n2. Done! It was simple.\n\n## Usage\n### Laravel 10 and below\nIn the place where you define routes (ex. `RouteServiceProvider`) you need to call a **Loader** class from the package.\n\nThe default class:\n```php\n\u003c?php\n\nnamespace App\\Providers;\n\nuse Illuminate\\Cache\\RateLimiting\\Limit;\nuse Illuminate\\Foundation\\Support\\Providers\\RouteServiceProvider as ServiceProvider;\nuse Illuminate\\Http\\Request;\nuse Illuminate\\Support\\Facades\\RateLimiter;\nuse Illuminate\\Support\\Facades\\Route;\n\nclass RouteServiceProvider extends ServiceProvider\n{\n    /**\n     * The path to your application's \"home\" route.\n     *\n     * Typically, users are redirected here after authentication.\n     *\n     * @var string\n     */\n    public const HOME = '/home';\n\n    /**\n     * Define your route model bindings, pattern filters, and other route configuration.\n     */\n    public function boot(): void\n    {\n        RateLimiter::for('api', function (Request $request) {\n            return Limit::perMinute(60)-\u003eby($request-\u003euser()?-\u003eid ?: $request-\u003eip());\n        });\n\n        $this-\u003eroutes(function () {\n            Route::middleware('api')\n                -\u003eprefix('api')\n                -\u003egroup(base_path('routes/api.php'));\n\n            Route::middleware('web')\n                -\u003egroup(base_path('routes/web.php'));\n        });\n    }\n}\n```\n\nChange to this:\n```php\n\u003c?php\n\nnamespace App\\Providers;\n\nuse Illuminate\\Cache\\RateLimiting\\Limit;\nuse Illuminate\\Foundation\\Support\\Providers\\RouteServiceProvider as ServiceProvider;\nuse Illuminate\\Http\\Request;\nuse Illuminate\\Support\\Facades\\RateLimiter;\nuse Twirelab\\LaravelRouter\\Facades\\Loader;\n\nclass RouteServiceProvider extends ServiceProvider\n{\n    /**\n     * The path to your application's \"home\" route.\n     *\n     * Typically, users are redirected here after authentication.\n     *\n     * @var string\n     */\n    public const HOME = '/home';\n\n    /**\n     * Define your route model bindings, pattern filters, and other route configuration.\n     */\n    public function boot(): void\n    {\n        RateLimiter::for('api', function (Request $request) {\n            return Limit::perMinute(60)-\u003eby($request-\u003euser()?-\u003eid ?: $request-\u003eip());\n        });\n\n        $this-\u003eroutes(function () {\n            Loader::group([\n                'prefix' =\u003e 'api',\n                'middleware' =\u003e 'api',\n            ])-\u003eloadFromDirectories(\n                app_path('Http/Controllers/API/**/*Controller.php'),\n            );\n\n            Loader::group([\n                'middleware' =\u003e 'web',\n            ])-\u003eloadFromDirectories(\n                app_path('Http/Controllers/*Controller.php'),\n            );\n        });\n    }\n}\n\n```\n\nFrom now, the Loader automatically imports Controllers from selected directories.\n\nIf you prefer, select controllers manually all the time. You can use the `loadControllers` method.\n\n```php\nuse Twirelab/LaravelRouter/Loader;\n\nLoader::group([\n    'prefix' =\u003e 'api',\n    'middleware' =\u003e 'api',\n])-\u003eloadControllers(\n    App\\Http\\Controllers\\FirstController::class,\n);\n\n// or\n\nLoader::group([\n    'prefix' =\u003e 'api',\n    'middleware' =\u003e 'api',\n])-\u003eloadControllers(\n    App\\Http\\Controllers\\FirstController::class,\n    App\\Http\\Controllers\\SecondController::class,\n);\n```\n\nIf don't want to use a group function (for example: you don't need a \"main\" group\nlike API or Web) you can use rest of functions directly.\n\n```php\nuse Twirelab/LaravelRouter/Facades/Loader;\n\nLoader::loadFromDirectories(\n    app_path('Http/Controllers/**/*Controller.php')\n);\n\n// or\n\nLoader::loadControllers(\n    App\\Http\\Controllers\\FirstController::class,\n);\n\n```\n\n### Laravel 11 and below\nIn the place where you define routes (ex. `api.php` or `web.php`) you need to call a **Loader** class from the package.\n\nFor example:\n```php\n\u003c?php\n\nuse Twirelab\\LaravelRouter\\Facades\\Loader;\n\nLoader::group([\n    'as' =\u003e 'v1.',\n    'prefix' =\u003e 'v1',\n])-\u003eloadFromDirectories(\n    app_path('Http/Controllers/V1/**/*Controller.php')\n);\n\n// or\n\nLoader::group([\n    'as' =\u003e 'v1.',\n    'prefix' =\u003e 'v1',\n])-\u003eloadControllers(\n    App\\Http\\Controllers\\FirstController::class,\n);\n\n```\n\n### Controller\nIf you want routes to load properly, you need to add the annotate to the controller class.\n\n```php\n\u003c?php\n\nnamespace App\\Http\\Controllers;\n\nuse App\\Http\\Controllers\\Controller;\nuse Twirelab\\LaravelRouter\\Annotations\\Router;\n\n#[Router]\nclass FirstController extends Controller\n{\n    // ... methods\n}\n```\n\n\u003e The \"route\" annotation works as a group function in Laravel.\n\n**Available options for Router annotation:**\n- _as_ - the name of a group,\n- _prefix_ - the prefix of a group,\n- _domain_ - the domain of a group,\n- _middlewares_ - the list of middlewares of a group,\n\nNow, we can define the first route for the method.\n\n```php\n\u003c?php\n\nnamespace App\\Http\\Controllers;\n\nuse App\\Http\\Controllers\\Controller;\nuse Twirelab\\LaravelRouter\\Annotations\\Method;\nuse Twirelab\\LaravelRouter\\Annotations\\Router;\nuse Twirelab\\LaravelRouter\\Enums\\Methods;\n\n#[Router]\nclass FirstController extends Controller\n{\n    #[Method(uri: '/', method: Methods::GET)]\n    public function index()\n    {\n        // ... logic of the method\n    }\n}\n```\n\nOur route: `GET - / - index \u003e FirstController@index`\n\n**Available options for Method annotation:**\n- _uri_ - the address URL for a route,\n- _method_ - the method of a route,\n- _name_ - the name of a route,\n- _middlewares_ - the list of middlewares of a route,\n- _where_ - the list of where's of a route,\n\n## Contributing\nFeel free to add a new issue! Please describe in detail your problem or idea and I will check your issue and respond - Thank you!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftwirelab%2Flaravel-router","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftwirelab%2Flaravel-router","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftwirelab%2Flaravel-router/lists"}