Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sebastiaanluca/laravel-router
THIS PACKAGE HAS BEEN DEPRECATED — An organized approach to handling routes in Laravel.
https://github.com/sebastiaanluca/laravel-router
laravel organize php router routes
Last synced: 3 months ago
JSON representation
THIS PACKAGE HAS BEEN DEPRECATED — An organized approach to handling routes in Laravel.
- Host: GitHub
- URL: https://github.com/sebastiaanluca/laravel-router
- Owner: sebastiaanluca
- License: mit
- Archived: true
- Created: 2016-04-06T14:04:41.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2020-10-19T15:36:05.000Z (about 4 years ago)
- Last Synced: 2024-07-19T03:08:31.159Z (4 months ago)
- Topics: laravel, organize, php, router, routes
- Language: PHP
- Homepage: https://sebastiaanluca.com
- Size: 130 KB
- Stars: 129
- Watchers: 8
- Forks: 12
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# Laravel Router
[![Latest stable release][version-badge]][link-packagist]
[![Software license][license-badge]](LICENSE.md)
[![Build status][travis-badge]][link-travis]
[![Total downloads][downloads-badge]][link-packagist]
[![Total stars][stars-badge]][link-github][![Read my blog][blog-link-badge]][link-blog]
[![View my other packages and projects][packages-link-badge]][link-packages]
[![Follow @sebastiaanluca on Twitter][twitter-profile-badge]][link-twitter]
[![Share this package on Twitter][twitter-share-badge]][link-twitter-share]__An organized approach to handling routes in Laravel.__
This package provides you with an easy-to-use system to separate route logic into __routers__ based on functionality while also providing additional functionality. A replacement for those bulky `web.php` and `api.php` route files that are often lacking any structure and break Laravel structure conventions of separating everything in classes instead of regular PHP files.
Do note that it *changes nothing to the way you define your routes*. It's just a way of organizing them. Optionally you can use the additional functionality it provides, but that's not a requirement.
## Table of contents
* [Requirements](#requirements)
* [How to install](#how-to-install)
+ [Further optional setup](#further-optional-setup)
* [How to use](#how-to-use)
+ [Creating a router](#creating-a-router)
+ [Registering the router](#registering-the-router)
- [Manually registering the router](#manually-registering-the-router)
* [Optional features](#optional-features)
+ [Common route parameter patterns](#common-route-parameter-patterns)
+ [Full-domain routing](#full-domain-routing)
* [License](#license)
* [Change log](#change-log)
* [Testing](#testing)
* [Contributing](#contributing)
* [Security](#security)
* [Credits](#credits)
* [About](#about)## Requirements
- PHP 7.3 or higher
- Laravel 7.0 or higherLooking for support for earlier versions? Try out any of the previous package versions.
## How to install
Just add the package to your project using Composer and Laravel will auto-discover it:
```bash
composer require sebastiaanluca/laravel-router
```### Further optional setup
If you want to be able to register your routers **in a single place**, add the `RegistersRouters` trait to your HTTP kernel (found at `App\Http\Kernel`):
```php
router->group(['middleware' => ['web', 'guest']], function () {$this->router->get('/users', function () {
return view('users.index');
});
});
}
}
```The `map` method is where you should define your routes and is the *only* requirement when using a router. The Laravel routing instance is automatically resolved from the IoC container, so you can use any standard routing functionality you want. Of course you can also use the `Route` facade.
### Registering the router
To automatically have the framework load your router and map its routes, [add the trait](#further-optional-setup) and add the router to the `$routers` array in your application's HTTP kernel class:
```php
/**
* The application routers to automatically boot.
*
* @var array
*/
protected $routers = [
\App\Http\Routers\UserRouter::class,
];
```#### Manually registering the router
If you don't want to or can't add the trait to the kernel, you can also register the router manually by just instantiating it (in a service provider for instance). The parent base router will automatically resolve all dependencies and call the `map` method on your router.
```php
app(\App\Http\Routers\UserRouter::class);
```Especially useful in packages!
## Optional features
To use the following optional features, register the `RegisterRoutePatterns` class:
```php
where('uuid', '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}');
```Just use the `{uuid}` or any other pattern in your route:
```php
$this->router->get('user/activations/{uuid}', function ($uuid) {
return view('users.activations.show');
});
```### Full-domain routing
Another great feature of Laravel is [sub-domain routing](https://laravel.com/docs/5.1/routing#route-groups) which allows you to handle multiple subdomains within a single Laravel project. The only caveat there is that it only does that and doesn't handle full domains.
Laravel Router fixes that for you so you can direct multiple domains to a single Laravel project and handle them all at once. Simply define a route group with the `{domain}` pattern and use it in your callback or controller:
```php
$this->router->group(['domain' => '{domain}'], function () {$this->router->get('user/{id}', function ($domain, $id) {
return 'You\'re visiting from ' . $domain;
});});
```## License
This package operates under the MIT License (MIT). Please see [LICENSE](LICENSE.md) for more information.
## Change log
Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.
## Testing
``` bash
composer install
composer test
```## Contributing
Please see [CONTRIBUTING](CONTRIBUTING.md) and [CONDUCT](CONDUCT.md) for details.
## Security
If you discover any security related issues, please email [[email protected]][link-author-email] instead of using the issue tracker.
## Credits
- [Sebastiaan Luca][link-github-profile]
- [All Contributors][link-contributors]## About
My name is Sebastiaan and I'm a freelance Laravel developer specializing in building custom Laravel applications. Check out my [portfolio][link-portfolio] for more information, [my blog][link-blog] for the latest tips and tricks, and my other [packages][link-packages] to kick-start your next project.
Have a project that could use some guidance? Send me an e-mail at [[email protected]][link-author-email]!
[version-badge]: https://img.shields.io/packagist/v/sebastiaanluca/laravel-router.svg?label=stable
[license-badge]: https://img.shields.io/badge/license-MIT-informational.svg
[travis-badge]: https://img.shields.io/travis/sebastiaanluca/laravel-router/master.svg
[downloads-badge]: https://img.shields.io/packagist/dt/sebastiaanluca/laravel-router.svg?color=brightgreen
[stars-badge]: https://img.shields.io/github/stars/sebastiaanluca/laravel-router.svg?color=brightgreen[blog-link-badge]: https://img.shields.io/badge/link-blog-lightgrey.svg
[packages-link-badge]: https://img.shields.io/badge/link-other_packages-lightgrey.svg
[twitter-profile-badge]: https://img.shields.io/twitter/follow/sebastiaanluca.svg?style=social
[twitter-share-badge]: https://img.shields.io/twitter/url/http/shields.io.svg?style=social[link-github]: https://github.com/sebastiaanluca/laravel-router
[link-packagist]: https://packagist.org/packages/sebastiaanluca/laravel-router
[link-travis]: https://travis-ci.org/sebastiaanluca/laravel-router
[link-contributors]: ../../contributors[link-portfolio]: https://www.sebastiaanluca.com
[link-blog]: https://blog.sebastiaanluca.com
[link-packages]: https://packagist.org/packages/sebastiaanluca
[link-twitter]: https://twitter.com/sebastiaanluca
[link-twitter-share]: https://twitter.com/home?status=Check%20out%20this%20nifty%20way%20of%20organizing%20your%20%23Laravel%20routes!%20https%3A//github.com/sebastiaanluca/laravel-router%20via%20%40sebastiaanluca
[link-github-profile]: https://github.com/sebastiaanluca
[link-author-email]: mailto:[email protected]