Download the PHP package dentro/yalr without Composer
On this page you can find all versions of the php package dentro/yalr. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Package yalr
Short Description Class base routing for laravel application.
License MIT
Informations about the package yalr
YALR (Yet Another Laravel Router)
Define Laravel routes in different ways using Route Attribute
Previously known as jalameta/router.
TABLE OF CONTENT
- Installation
- Requirements
- Applying into your project
- Usage
- Class Wrapper Route
- Creating New Route
- Route Configuration
- Class Structure
- Using Controller
- Route Prefix
- Route Name
- Preloads
- Route Attribute
- Available Class Target
- Available Method Target
- Added To Configuration Route
- Class Wrapper Route
Installation
Using composer :
Requirements
Laravel | Yalr |
---|---|
8.x | ^1.0 |
9.x | ^1.1 |
10.x | ^1.2 |
11.x | ^1.3 |
Applying into your project
Run command in your project
If you're deciding to remove the original laravel routes, you might add --remove
option within the command. So the
command will be
YALR will configure the routes for you, the Laravel default
routes
folder will be deleted. So backup your defined routes first.
Usage
Class Wrapper Route
Class wrapper route is our effort to make routing in laravel more expressive and separated. We usually make route that
representative with namespace for easy to understand. For example, class App\Admin\TransactionRoute
will represent
route /app/admin/transaction
.
Creating new route
To make a new route just run:
After running command above, the route named DefaultRoute
will appear in app/Http/Routes/DefaultRoute.php
. After
creating routes, it will not be loaded automatically, you must register the Route Class in the route configuration.
make:route options
- Inject Inject is useful options to auto adding the route class name within route configuration, so you don't need to add it manually. E.g:
Command above will make the Default route within the web groups that defined in config/routes.php
.
-
Controller The controller option will generate the route and the controller used by the route. So you don't need to run 2 artisan command to create a new controller and route.
- Help Shows YALR command helps
Routes Configuration
Below is an example of YALR configurations.
As you can see, groups
index is group configuration, you can pass any laravel options there such as as
, domain
,
middleware
, prefix
, etc. Afterward, the web
and api
are group index defined before in the groups
index. It is an array of route class names.
Class Structure
After creating a route with the command, we will see the example of the generated file.
After creating a route with the command, we will see the example of the generated file. We can define routes within the register method. All you need is to call $this->router as a router instance. Then, we can invoke the laravel routing method such as post, put, etc. See Laravel Routing Docs.
Avoid using closure action, otherwise your application will encounter error when routes were cached.
Using Controller
From create route command, we know we can pass the controller namespace. The created controller will show up in the route class as a controller method.
The route above is equal with
This package want to solve those duplicated namespace and class name several times as we define the routes.
Or if you don't want to use the controller in the route class, you can pass the second parameter of $this->uses()
method with the controller class name to be used, E.g : $this->uses('login', LoginController::class)
.
Route Prefix
Override the route prefix defined in the class property. Default prefix is '/';
protected string $prefix = '/home';
The route above is equal with
Route Name
You need to define the route name property within the route class
protected string $name = 'home';
Later we can use $this->name()
method for adding separation with dot (.) between the route group name, and the single
route name
It equal with
Preloads
Preloads always run even though routes been cached. It might be the good place to put route model binding and rate limiter there.
Example :
Route Attribute
PHP 8 comes up with a nice feature called Attribute
see this link for the detail. So we added those feature to this package for us to create something like the example below.
Available Class Target
Available Method Target
Added To Configuration Route
just put class to your route configuration and yalr will figure it out what to do with your controller.
All versions of yalr with dependencies
illuminate/support Version ^8.0|^9.0|^10.0|^11.0
illuminate/console Version ^8.0|^9.0|^10.0|^11.0
illuminate/routing Version ^8.0|^9.0|^10.0|^11.0
illuminate/filesystem Version ^8.0|^9.0|^10.0|^11.0
illuminate/contracts Version ^8.0|^9.0|^10.0|^11.0