Download the PHP package micaeldias/laravel-single-file-routes without Composer
On this page you can find all versions of the php package micaeldias/laravel-single-file-routes. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download micaeldias/laravel-single-file-routes
More information about micaeldias/laravel-single-file-routes
Files in micaeldias/laravel-single-file-routes
Package laravel-single-file-routes
Short Description Streamlined route management for your Laravel applications.
License MIT
Homepage https://github.com/micaeldias/laravel-single-file-routes
Informations about the package laravel-single-file-routes
Single file routes for Laravel
Single file routes allows you to co-locate everything about a route into a single file. See the route method, URI, middleware, and it's behaviour at a glance without the need to keep track of multiple files.
You can still register routes like you're used to in conjunction with this package, this is not an all-in package.
Compatibility
Laravel version | PHP version | Package version |
---|---|---|
8 | 7.4 - 8.1 | 1 |
9 - 10 | 8.0 - 8.2 | 2 |
9 - 10 | 8.0 - 8.2 | 3 |
Installation
You may install single file routes into your project with:
After installing, publish the assets using the single-file-routes:install
Artisan command:
After publishing single file routes' assets, its primary configuration file will be located at config/single-file-routes.php
.
Usage
Single Action Controllers
To register a route in a single action controller, simply add the Route
attribute to the class itself:
Basic Controllers
To register a route in a basic controller, you need to the Route
attribute to the method instead:
Route Groups
To use a route group, you first need to create one. This is easily done using the artisan command make:route-group
explained below.
The route group extends the following interface:
Once you've created your desired route group, you can start adding routes under it. Let's say we create an ApiRouteGroup
, to use it on a route we can simply pass the group
param on the Route
attribute, as such:
Route names
By default, routes' names are the same as their definition meaning you can simply pass the class name in Laravel's route
method to get the URL.
Single Action Controllers
Basic Controllers
Custom Route Names
If you don't like having the route name the same as it's definition you can pass the name
param on the Route
attribute:
Adding middleware
You can use any middleware supported by Laravel directly in the route or on route groups to be used by all routes under it.
Route Group Middleware
To add middleware to the route group, return it from the middleware()
function:
Specific Route Middleware
If you need to add middleware to a single Route, you can pass the middleware
param on the Route
attribute:
Multiple Routes
If for some reason you need a controller to respond to multiple URIs, you can stack as many Routes as needed:
This will make /user
and /users
have the same behaviour.
Route Caching
Laravel's route caching is fully supported.
In fact, due to how routes are discovered, it's highly recommended that you do cache your routes in production.
Artisan Commands
Generate Route Groups
You can easily create a route group using the make:route-group
Artisan command:
Let's say we want to create an API route group:
Here's how the generated class would look like:
Generate Routes
We only support generating single action controllers using the make:route
command.
Follow the prompts to generate the desired route:
Here's how the generated class would look like:
Keep in mind that the route generators were created for your convenience, but you're of course free to manually create routes or groups if it's simpler for your use-case.
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
- Micael Dias
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-single-file-routes with dependencies
haydenpierce/class-finder Version ^0.5.3
illuminate/contracts Version ^9.0|^10.0
spatie/laravel-package-tools Version ^1.0