Download the PHP package bfg/route without Composer
On this page you can find all versions of the php package bfg/route. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Package route
Short Description Auto register routes using PHP attributes
License MIT
Homepage https://github.com/bfg/route
Informations about the package route
Use PHP 8 attributes to register routes in a Laravel app
This package provides annotations to automatically register routes. Here's a quick example:
This attribute will automatically register this route:
Installation
You can install the package via composer:
Usage
In your RouteServiceProvider
, delete where your controllers are located and he will do the rest for you:
The package provides several annotations that should be put on controller classes and methods. These annotations will be used to automatically register routes
Adding a GET route
This attribute will automatically register this route:
Using other HTTP verbs
We have left no HTTP verb behind. You can use these attributes on controller methods.
Specify a route name
All HTTP verb attributes accept a parameter named name
that accepts a route name.
This attribute will automatically register this route:
Adding middleware
All HTTP verb attributes accept a parameter named middleware
that accepts a middleware class or an array of middleware classes.
This annotation will automatically register this route:
To apply middleware on all methods of a class you can use the Middleware
attribute. You can mix this with applying attribute on a method.
These annotations will automatically register these routes:
Specifying a prefix
You can use the Prefix
annotation on a class to prefix the routes of all methods of that class.
These annotations will automatically register these routes:
Specifying a domain
You can use the Domain
annotation on a class to prefix the routes of all methods of that class.
These annotations will automatically register these routes:
Deployment
As stated in the documentation which you can see here. After you cache your routes ...
... scanning of your classes will be disabled.
Testing
Inspired by
I took this package into the service and reworked it a little, added a couple of functions, caching and added the ability to extend it a little, I plan to support a more advanced API as far as possible.
License
The MIT License (MIT). Please see License File for more information.