{"id":19258926,"url":"https://github.com/lassehaslev/laravel-package-router","last_synced_at":"2025-06-22T06:02:30.969Z","repository":{"id":57012595,"uuid":"76110073","full_name":"LasseHaslev/laravel-package-router","owner":"LasseHaslev","description":"Your package routes made REALLY simple!","archived":false,"fork":false,"pushed_at":"2016-12-12T16:57:04.000Z","size":42,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-23T18:16:58.502Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/LasseHaslev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-12-10T12:04:23.000Z","updated_at":"2016-12-10T12:04:39.000Z","dependencies_parsed_at":"2022-08-21T15:10:50.865Z","dependency_job_id":null,"html_url":"https://github.com/LasseHaslev/laravel-package-router","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/LasseHaslev/laravel-package-router","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LasseHaslev%2Flaravel-package-router","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LasseHaslev%2Flaravel-package-router/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LasseHaslev%2Flaravel-package-router/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LasseHaslev%2Flaravel-package-router/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LasseHaslev","download_url":"https://codeload.github.com/LasseHaslev/laravel-package-router/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LasseHaslev%2Flaravel-package-router/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261243972,"owners_count":23129633,"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":[],"created_at":"2024-11-09T19:14:49.350Z","updated_at":"2025-06-22T06:02:25.952Z","avatar_url":"https://github.com/LasseHaslev.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# lassehaslev/laravel-package-router\n\u003e Your package routes made REALLY simple!\n\n## Install\nRun ```composer require lassehaslev/laravel-package-router```\n\n## Usage\nThis is a [global/universal](https://github.com/LasseHaslev/UniversalObjects) object to handle your routes.\n\nEven tough this package is made to handle routes in packages, it is no trouble using it wherever you want.\n\n#### Register your routes\nAdd your routes in ServiceProvider@register\n```php\n// It is recommended that you extend the class\nclass MyRouter extends LasseHaslev\\LaravelPackageRouter\\PackageRouter {}\n\n// Create new router\n$router = MyRouter::create();\n\n// Add route to router\n$router-\u003eadd( 'users.index', [\n    'uri'=\u003e'users',\n    'as'=\u003e'users.index',\n    'uses'=\u003e'Controller@index',\n] )\n// You can also chain add\n-\u003eapp( 'users.update', [\n    'uri'=\u003e'users/{user}',\n    'method'=\u003e'put',\n    'uses'=\u003e'Controller@index',\n] );\n\n-\u003eadd( 'images.index', [\n    'uri'=\u003e'images',\n    'uses'=\u003e'Controller@index',\n] )\n-\u003eadd( 'images.store', [\n    'uri'=\u003e'images',\n    'method'=\u003e'post',\n    'uses'=\u003e'Controller@store',\n] )\n```\n\n#### Register routes\nNote that you can get the reference of the router only by calling ```MyRouter::get()``` even though you created it another place. \nThis is because it extends [LasseHaslev\\UniversalObjects\\Object](https://github.com/LasseHaslev/UniversalObjects).\n```php\n// Usually in your routes/web.php\n$myRouter = MyRouter::get();\n\n$myRouter-\u003eroute( 'images.index' ); // \"/images\"\nRoute::group([ 'prefix'=\u003e'backend', 'middleware'=\u003e'auth' ], function( $router ) use ( $myRouter ) {\n    $myRouter-\u003eroutes( 'users' ); // \"/backend/users\" and \"/backend/users/{user}\"\n    $myRouter-\u003eroute( 'images.store' ); // \"/backend/images\"\n});\n```\n\n#### Api\n```php\n// Get the router\n$router = MyRouter::create(); // MyRouter::get();\n\n// Add route\n$router-\u003eadd( $reference, [\n    'uri'=\u003e'users',\n    'method'=\u003e'get',\n    'as'=\u003e'users.index',\n    'uses'=\u003e'Controller@index',\n    // 'middleware'=\u003e'auth', // You can add middleware if you want to\n] );\n\n// Get all routes\n$router-\u003eroutes(); // Set routes for users.index, images.index and images.show\n\n// Get all routes under images namespace\n$router-\u003eroutes( 'images' ); // Set routes for images.index and images.show\n\n// Get single route\n$router-\u003eroute( 'images.index' );\n```\n\n## Development\n``` bash\n# Install dependencies\ncomposer install\n\n# Install dependencies for automatic tests\nyarn\n\n# Run one time\nnpm run test\n\n# Automaticly run test on changes\nnpm run dev\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flassehaslev%2Flaravel-package-router","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flassehaslev%2Flaravel-package-router","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flassehaslev%2Flaravel-package-router/lists"}